Spaces:
Runtime error
Runtime error
File size: 2,959 Bytes
39eb06d f415c95 b1426d3 f415c95 d5e14b5 5ac02d2 0ffe6c3 5ac02d2 f415c95 39eb06d f459835 d5e14b5 7e29a25 f415c95 d5e14b5 427a3a2 f415c95 d5e14b5 f415c95 7e29a25 0ffe6c3 7e29a25 0ffe6c3 f415c95 d5e14b5 f415c95 3d94876 d5e14b5 3d94876 0ffe6c3 3d94876 73b6f4f 3d94876 39eb06d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
<script lang="ts">
import { type Conversation } from "$lib/types.js";
import { watch } from "runed";
import { GENERATION_CONFIG_KEYS, GENERATION_CONFIG_SETTINGS } from "./generation-config-settings.js";
import { maxAllowedTokens } from "./utils.js";
import { isNumber } from "$lib/utils/is.js";
import IconX from "~icons/carbon/close";
interface Props {
conversation: Conversation;
classNames?: string;
}
let { conversation = $bindable(), classNames = "" }: Props = $props();
const maxTokens = $derived(maxAllowedTokens(conversation));
watch(
() => maxTokens,
() => {
const curr = conversation.config.max_tokens;
if (!curr || curr <= maxTokens) return;
conversation.config.max_tokens = maxTokens;
}
);
</script>
<div class="flex flex-col gap-y-7 {classNames}">
{#each GENERATION_CONFIG_KEYS as key}
{@const { label, min, step } = GENERATION_CONFIG_SETTINGS[key]}
{@const isMaxTokens = key === "max_tokens"}
{@const max = isMaxTokens ? maxTokens : GENERATION_CONFIG_SETTINGS[key].max}
<div>
<div class="flex items-center justify-between">
<label for={key} class="mb-0.5 block text-sm font-medium text-gray-900 dark:text-white">
{label}
</label>
<div class="flex items-center gap-2">
{#if !isMaxTokens || isNumber(conversation.config[key])}
<input
type="number"
class="w-20 rounded-sm border bg-transparent px-1 py-0.5 text-right text-sm dark:border-gray-700"
{min}
{max}
{step}
bind:value={conversation.config[key]}
/>
{/if}
{#if isMaxTokens && isNumber(conversation.config[key])}
<button class="btn-mini" onclick={() => (conversation.config[key] = undefined)}> <IconX /> </button>
{:else if isMaxTokens}
<button class="btn-mini" onclick={() => (conversation.config[key] = maxTokens / 2)}> set </button>
{/if}
</div>
</div>
{#if !isMaxTokens || isNumber(conversation.config[key])}
<input
id={key}
type="range"
{min}
{max}
{step}
bind:value={conversation.config[key]}
class="h-2 w-full cursor-pointer appearance-none rounded-lg bg-gray-200 accent-black dark:bg-gray-700 dark:accent-blue-500"
/>
{/if}
</div>
{/each}
<div class="mt-2">
<label class="flex cursor-pointer items-center justify-between">
<input type="checkbox" bind:checked={conversation.streaming} class="peer sr-only" />
<span class="text-sm font-medium text-gray-900 dark:text-gray-300">Streaming</span>
<div
class="peer relative h-5 w-9 rounded-full bg-gray-200 peer-checked:bg-black peer-focus:outline-hidden after:absolute after:start-[2px] after:top-[2px] after:h-4 after:w-4 after:rounded-full after:border after:border-gray-300 after:bg-white after:transition-all after:content-[''] peer-checked:after:translate-x-full peer-checked:after:border-white dark:border-gray-600 dark:bg-gray-700 dark:peer-checked:bg-blue-600"
></div>
</label>
</div>
</div>
|