diff --git a/web/src/components/llm-setting-items/next.tsx b/web/src/components/llm-setting-items/next.tsx new file mode 100644 index 000000000..31e63068b --- /dev/null +++ b/web/src/components/llm-setting-items/next.tsx @@ -0,0 +1,219 @@ +import { LlmModelType, ModelVariableType } from '@/constants/knowledge'; +import { useTranslate } from '@/hooks/common-hooks'; +import { useComposeLlmOptionsByModelTypes } from '@/hooks/llm-hooks'; +import { camelCase } from 'lodash'; +import { useCallback } from 'react'; +import { useFormContext } from 'react-hook-form'; +import { + FormControl, + FormField, + FormItem, + FormLabel, + FormMessage, +} from '../ui/form'; +import { Input } from '../ui/input'; +import { + Select, + SelectContent, + SelectGroup, + SelectItem, + SelectLabel, + SelectTrigger, + SelectValue, +} from '../ui/select'; +import { FormSlider } from '../ui/slider'; +import { Switch } from '../ui/switch'; + +interface SliderWithInputNumberFormFieldProps { + name: string; + label: string; + checkName: string; + max: number; + min?: number; + step?: number; +} + +function SliderWithInputNumberFormField({ + name, + label, + checkName, + max, + min = 0, + step = 1, +}: SliderWithInputNumberFormFieldProps) { + const { control, watch } = useFormContext(); + const { t } = useTranslate('chat'); + const disabled = !watch(checkName); + + return ( + ( + +
+ {t(label)} + ( + + + + + + + )} + /> +
+ +
+ + +
+
+ +
+ )} + /> + ); +} + +interface LlmSettingFieldItemsProps { + prefix?: string; +} + +export function LlmSettingFieldItems({ prefix }: LlmSettingFieldItemsProps) { + const form = useFormContext(); + const { t } = useTranslate('chat'); + const modelOptions = useComposeLlmOptionsByModelTypes([ + LlmModelType.Chat, + LlmModelType.Image2text, + ]); + + const parameterOptions = Object.values(ModelVariableType).map((x) => ({ + label: t(camelCase(x)), + value: x, + })); + + const getFieldWithPrefix = useCallback( + (name: string) => { + return `${prefix}.${name}`; + }, + [prefix], + ); + + return ( +
+ ( + + {t('model')} + + + + + + )} + /> + ( + + {t('freedom')} + + + + + + )} + /> + + + + + +
+ ); +} diff --git a/web/src/hooks/chat-hooks.ts b/web/src/hooks/chat-hooks.ts index 843a9e70c..44ceda768 100644 --- a/web/src/hooks/chat-hooks.ts +++ b/web/src/hooks/chat-hooks.ts @@ -119,6 +119,26 @@ export const useFetchNextDialogList = () => { return { data, loading, refetch }; }; +export const useFetchChatAppList = () => { + const { + data, + isFetching: loading, + refetch, + } = useQuery({ + queryKey: ['fetchChatAppList'], + initialData: [], + gcTime: 0, + refetchOnWindowFocus: false, + queryFn: async () => { + const { data } = await chatService.listDialog(); + + return data?.data ?? []; + }, + }); + + return { data, loading, refetch }; +}; + export const useSetNextDialog = () => { const queryClient = useQueryClient(); diff --git a/web/src/hooks/llm-hooks.tsx b/web/src/hooks/llm-hooks.tsx index 14520fb95..2a3451dbc 100644 --- a/web/src/hooks/llm-hooks.tsx +++ b/web/src/hooks/llm-hooks.tsx @@ -116,7 +116,11 @@ export const useComposeLlmOptionsByModelTypes = ( ) => { const allOptions = useSelectLlmOptionsByModelType(); - return modelTypes.reduce((pre, cur) => { + return modelTypes.reduce< + (DefaultOptionType & { + options: { label: JSX.Element; value: string; disabled: boolean }[]; + })[] + >((pre, cur) => { const options = allOptions[cur]; options.forEach((x) => { const item = pre.find((y) => y.label === x.label); diff --git a/web/src/pages/next-chats/chat/app-settings/chat-model-settings.tsx b/web/src/pages/next-chats/chat/app-settings/chat-model-settings.tsx index 6b7d69c07..92c79c122 100644 --- a/web/src/pages/next-chats/chat/app-settings/chat-model-settings.tsx +++ b/web/src/pages/next-chats/chat/app-settings/chat-model-settings.tsx @@ -1,9 +1,43 @@ +import { LlmSettingFieldItems } from '@/components/llm-setting-items/next'; +import { + FormControl, + FormField, + FormItem, + FormLabel, + FormMessage, +} from '@/components/ui/form'; +import { Textarea } from '@/components/ui/textarea'; +import { useTranslate } from '@/hooks/common-hooks'; +import { useFormContext } from 'react-hook-form'; import { Subhead } from './subhead'; export function ChatModelSettings() { + const { t } = useTranslate('chat'); + const form = useFormContext(); + return (
Model Setting +
+ ( + + {t('system')} + +