feat: 添加 LoRA 类型选择组件,支持保存和反馈机制
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
<script lang="ts">
|
||||
import DatasetName from './meta-form/DatasetName.svelte';
|
||||
import SelectLoraType from './meta-form/SelectLoraType.svelte';
|
||||
import SelectModel from './meta-form/SelectModel.svelte';
|
||||
</script>
|
||||
|
||||
<div class="flex flex-col gap-2 px-4 py-4">
|
||||
<DatasetName />
|
||||
<SelectModel />
|
||||
<SelectLoraType />
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
<script lang="ts">
|
||||
import { activeDatasetMeta, updateActiveDatasetMeta } from '$lib/stores/dataset';
|
||||
import { LoRATypeChoices, type LoRATypes } from '$lib/types/models';
|
||||
import { createSaveFeedbackController, type SaveFeedbackState } from '$lib/utils/form-save';
|
||||
import { onDestroy, onMount } from 'svelte';
|
||||
import { get } from 'svelte/store';
|
||||
|
||||
let selected: LoRATypes | null = $state(null);
|
||||
let saveFeedback = $state<SaveFeedbackState>('idle');
|
||||
|
||||
const feedback = createSaveFeedbackController((state) => {
|
||||
saveFeedback = state;
|
||||
});
|
||||
|
||||
onMount(() => {
|
||||
const currentType = get(activeDatasetMeta)?.loraType;
|
||||
const match = LoRATypeChoices.find((item) => item.value === currentType);
|
||||
selected = match?.value ?? null;
|
||||
});
|
||||
|
||||
onDestroy(() => {
|
||||
feedback.dispose();
|
||||
});
|
||||
|
||||
async function saveLoraType() {
|
||||
if (!selected) {
|
||||
feedback.markNotUpdated();
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await updateActiveDatasetMeta({ loraType: selected });
|
||||
feedback.markUpdated();
|
||||
} catch (error) {
|
||||
console.error('Failed to save lora type:', error);
|
||||
feedback.markNotUpdated();
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<label
|
||||
class={[
|
||||
'input w-fit in-focus-within:outline-0 transition-colors duration-300 ease-out',
|
||||
saveFeedback === 'updated' && 'border-green-500',
|
||||
saveFeedback === 'not-updated' && 'border-red-500',
|
||||
]}>
|
||||
<span class="label min-w-[10em]">LoRA Type</span>
|
||||
<select bind:value={selected} onchange={saveLoraType} class="min-w-[20em] focus:outline-0">
|
||||
{#each LoRATypeChoices as loraType}
|
||||
<option value={loraType.value}>{loraType.label}</option>
|
||||
{/each}
|
||||
</select>
|
||||
</label>
|
||||
Reference in New Issue
Block a user