Skip to content

Commit

Permalink
WIP KVSettings
Browse files Browse the repository at this point in the history
  • Loading branch information
amengus87 committed Aug 29, 2024
1 parent ea12078 commit fe89a85
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 31 deletions.
54 changes: 54 additions & 0 deletions frontend/src/components/custom/kv-settings.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<script setup lang="ts">
import { computed } from 'vue';
import { $t } from '@/locales';
defineOptions({
name: 'KVSettings'
});
const settingsModel = defineModel<string[]>('settings', { required: true });
const settings = computed({
get() {
// console.log(settingsModel.value);
if (!settingsModel.value) {
return [];
}
// Split settingsModel into key-value pairs
const test = settingsModel.value.map(item => {
const [key, value] = item.split('=');
return { key, value: value || '' };
});
// console.log(test);
return test;
},
set(newValue) {
// console.log(newValue);
settingsModel.value = newValue.map(item => (item ? `${item.key}=${item.value}` : ''));
}
});
</script>

<template>
<NDynamicInput v-model:value="settings">
<template #create-button-default>
{{ $t('common.add') }}
</template>
<template #default="{ index }">
<div class="flex">
<NFormItem :path="`settings[${index}].key`" ignore-path-change :show-label="false" class="flex-auto">
<NInput v-model:value="settings[index].key" :placeholder="$t('common.key')" @keydown.enter.prevent />
</NFormItem>
<div class="mt-1 w-14 flex-auto text-center align-middle">=</div>
<NFormItem :path="`settings[${index}].value`" ignore-path-change :show-label="false" class="flex-auto">
<NInput v-model:value="settings[index].value" :placeholder="$t('common.value')" @keydown.enter.prevent />
</NFormItem>
</div>
</template>
</NDynamicInput>
</template>

<style scoped></style>
1 change: 1 addition & 0 deletions frontend/src/typings/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ declare module 'vue' {
IconMdiKeyboardReturn: typeof import('~icons/mdi/keyboard-return')['default']
IconMdiRefresh: typeof import('~icons/mdi/refresh')['default']
IconUilSearch: typeof import('~icons/uil/search')['default']
KvSettings: typeof import('./../components/custom/kv-settings.vue')['default']
LangSwitch: typeof import('./../components/common/lang-switch.vue')['default']
LookForward: typeof import('./../components/custom/look-forward.vue')['default']
MenuToggler: typeof import('./../components/common/menu-toggler.vue')['default']
Expand Down
40 changes: 23 additions & 17 deletions frontend/src/views/infrastructure/silo-list/modules/silo-edit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { $t } from '@/locales';
import { translateOptions } from '@/utils/common';
import { embeddingModelOptions, ingestorLoaderOptions, vectorStoreOptions } from '@/constants/business';
import { fetchUpsertSilo } from '@/service/api';
import KVSettings from '../../../../components/custom/kv-settings.vue';
defineOptions({
name: 'SiloEdit'
Expand Down Expand Up @@ -45,9 +46,16 @@ type Model = Pick<Api.SiloManage.Silo, 'uuid'>;
const model: Model = reactive(createDefaultModel());
function createDefaultModel(): Model {
function createDefaultModel(): Api.SiloManage.Silo {
return {
uuid: NIL_UUID
uuid: NIL_UUID,
name: '',
vectorStore: null,
embeddingModel: null,
ingestorLoader: null,
vectorStoreSettings: null,
embeddingSettings: null,
ingestorSettings: null
};
}
Expand All @@ -60,7 +68,6 @@ const rules: Record<RuleKey, App.Global.FormRule> = {
function handleInitModel() {
Object.assign(model, createDefaultModel());
if (props.operateType === 'edit' && props.rowData) {
Object.assign(model, props.rowData);
}
Expand Down Expand Up @@ -109,20 +116,7 @@ watch(visible, () => {
/>
<NCollapse>
<NCollapseItem :title="$t('common.settings')">
<NDynamicInput>
<template #create-button-default>
{{ $t('common.add') }}
</template>
<div class="flex">
<NFormItem ignore-path-change :show-label="false" class="flex-auto">
<NInput :placeholder="$t('common.key')" @keydown.enter.prevent />
</NFormItem>
<div class="mt-1 w-14 flex-auto text-center align-middle">=</div>
<NFormItem ignore-path-change :show-label="false" class="flex-auto">
<NInput :placeholder="$t('common.value')" @keydown.enter.prevent />
</NFormItem>
</div>
</NDynamicInput>
<KVSettings v-model:settings="model.vectorStoreSettings" />
</NCollapseItem>
</NCollapse>
<NDivider title-placement="left">
Expand All @@ -133,7 +127,13 @@ watch(visible, () => {
:placeholder="$t('dRAGon.embeddingModel')"
:options="translateOptions(embeddingModelOptions)"
clearable
class="mb-4"
/>
<NCollapse>
<NCollapseItem :title="$t('common.settings')">
<KVSettings v-model:settings="model.embeddingSettings" />
</NCollapseItem>
</NCollapse>
<NDivider title-placement="left">
{{ $t('dRAGon.ingestorLoader') }}
</NDivider>
Expand All @@ -142,7 +142,13 @@ watch(visible, () => {
:placeholder="$t('dRAGon.ingestorLoader')"
:options="translateOptions(ingestorLoaderOptions)"
clearable
class="mb-4"
/>
<NCollapse>
<NCollapseItem :title="$t('common.settings')">
<KVSettings v-model:settings="model.ingestorSettings" />
</NCollapseItem>
</NCollapse>
</NForm>
<template #footer>
<NSpace :size="16">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<script setup lang="ts">
import { computed } from 'vue';
import { $t } from '@/locales';
import { useFormRules, useNaiveForm } from '@/hooks/common/form';
import { useNaiveForm } from '@/hooks/common/form';
import { vectorStoreOptions } from '@/constants/business';
import { translateOptions } from '@/utils/common';
Expand All @@ -20,17 +19,6 @@ const { formRef, validate, restoreValidation } = useNaiveForm();
const model = defineModel<Api.SiloManage.SiloSearchParams>('model', { required: true });
type RuleKey = Extract<keyof Api.SystemManage.UserSearchParams, 'userEmail' | 'userPhone'>;
const rules = computed<Record<RuleKey, App.Global.FormRule>>(() => {
const { patternRules } = useFormRules(); // inside computed to make locale reactive
return {
userEmail: patternRules.email,
userPhone: patternRules.phone
};
});
async function reset() {
await restoreValidation();
emit('reset');
Expand All @@ -44,7 +32,7 @@ async function search() {

<template>
<NCard :title="$t('common.search')" :bordered="false" size="small" class="card-wrapper">
<NForm ref="formRef" :model="model" :rules="rules" label-placement="left" :label-width="80">
<NForm ref="formRef" :model="model" label-placement="left" :label-width="80">
<NGrid responsive="screen" item-responsive>
<NFormItemGi span="24 s:12 m:6" label="UUID" path="uuid" class="pr-24px">
<NInput v-model:value="model.uuid" placeholder="UUID" @keyup.enter="search" />
Expand Down

0 comments on commit fe89a85

Please sign in to comment.