Files
ragflow/web/src/pages/next-chats/chat/app-settings/use-chat-setting-schema.tsx
_Chenbing 0af57ff772 fix(dataset, next-chats): Fix data form data acquisition logic And Optimize the chat settings interface and add language selection (#9629)
### What problem does this PR solve?

fix(dataset): data form data acquisition logic
fix(next-chats): Optimize the chat settings interface and add language
selection

- Replace form.formControl.trigger with form.trigger
- Use form.getValues() instead of form.formState.values
- Add language selection to support multiple languages
- Add default chat settings values
- Add new settings: icon, description, knowledge base ID, etc.

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)
- [x] New Feature (non-breaking change which adds functionality)
- [ ] Documentation Update
- [ ] Refactoring
- [ ] Performance Improvement
- [ ] Other (please describe):
2025-08-21 16:57:46 +08:00

55 lines
1.6 KiB
TypeScript

import {
LlmSettingEnabledSchema,
LlmSettingFieldSchema,
} from '@/components/llm-setting-items/next';
import { MetadataFilterSchema } from '@/components/metadata-filter';
import { rerankFormSchema } from '@/components/rerank';
import { vectorSimilarityWeightSchema } from '@/components/similarity-slider';
import { topnSchema } from '@/components/top-n-item';
import { useTranslate } from '@/hooks/common-hooks';
import { z } from 'zod';
export function useChatSettingSchema() {
const { t } = useTranslate('chat');
const promptConfigSchema = z.object({
quote: z.boolean(),
keyword: z.boolean(),
tts: z.boolean(),
empty_response: z.string().optional(),
prologue: z.string().optional(),
system: z.string().min(1, { message: t('systemMessage') }),
refine_multiturn: z.boolean(),
use_kg: z.boolean(),
parameters: z.array(
z.object({
key: z.string(),
optional: z.boolean(),
}),
),
tavily_api_key: z.string().optional(),
});
const formSchema = z.object({
name: z.string().min(1, { message: t('assistantNameMessage') }),
icon: z.array(z.instanceof(File)),
language: z.string().min(1, {
message: t('languageMessage'),
}),
description: z.string().optional(),
kb_ids: z.array(z.string()).min(0, {
message: t('knowledgeBasesMessage'),
}),
prompt_config: promptConfigSchema,
...rerankFormSchema,
llm_setting: z.object(LlmSettingFieldSchema),
...LlmSettingEnabledSchema,
llm_id: z.string().optional(),
...vectorSimilarityWeightSchema,
...topnSchema,
...MetadataFilterSchema,
});
return formSchema;
}