diff --git a/web/src/hooks/logic-hooks/use-build-options.ts b/web/src/hooks/logic-hooks/use-build-options.ts index 62370e9bd..e0d09bc6e 100644 --- a/web/src/hooks/logic-hooks/use-build-options.ts +++ b/web/src/hooks/logic-hooks/use-build-options.ts @@ -1,5 +1,6 @@ import { SwitchLogicOperator } from '@/constants/agent'; import { buildOptions } from '@/utils/form'; +import { useCallback } from 'react'; import { useTranslation } from 'react-i18next'; export function useBuildSwitchLogicOperatorOptions() { @@ -10,3 +11,21 @@ export function useBuildSwitchLogicOperatorOptions() { 'flow.switchLogicOperatorOptions', ); } + +export function useBuildModelTypeOptions() { + const { t } = useTranslation(); + + const buildModelTypeOptions = useCallback( + (list: string[]) => { + return list.map((x) => ({ + value: x, + label: t(`setting.modelTypes.${x}`), + })); + }, + [t], + ); + + return { + buildModelTypeOptions, + }; +} diff --git a/web/src/locales/en.ts b/web/src/locales/en.ts index 315d9d3a2..a15edf75d 100644 --- a/web/src/locales/en.ts +++ b/web/src/locales/en.ts @@ -1233,6 +1233,15 @@ Example: Virtual Hosted Style`, 'Vision Language Model with LMDeploy Engine (Experimental)', }, }, + modelTypes: { + chat: 'Chat', + embedding: 'Embedding', + rerank: 'Rerank', + sequence2text: 'sequence2text', + tts: 'TTS', + image2text: 'OCR', + speech2text: 'ASR', + }, }, message: { registered: 'Registered!', diff --git a/web/src/pages/user-setting/setting-model/modal/azure-openai-modal/index.tsx b/web/src/pages/user-setting/setting-model/modal/azure-openai-modal/index.tsx index f08770e07..fca1bd976 100644 --- a/web/src/pages/user-setting/setting-model/modal/azure-openai-modal/index.tsx +++ b/web/src/pages/user-setting/setting-model/modal/azure-openai-modal/index.tsx @@ -5,6 +5,7 @@ import { } from '@/components/dynamic-form'; import { Modal } from '@/components/ui/modal/modal'; import { useCommonTranslation, useTranslate } from '@/hooks/common-hooks'; +import { useBuildModelTypeOptions } from '@/hooks/logic-hooks/use-build-options'; import { IModalProps } from '@/interfaces/common'; import { IAddLlmRequestBody } from '@/interfaces/request/llm'; import { FieldValues } from 'react-hook-form'; @@ -19,6 +20,7 @@ const AzureOpenAIModal = ({ }: IModalProps & { llmFactory: string }) => { const { t } = useTranslate('setting'); const { t: tg } = useCommonTranslation(); + const { buildModelTypeOptions } = useBuildModelTypeOptions(); const fields: FormFieldConfig[] = [ { @@ -26,11 +28,7 @@ const AzureOpenAIModal = ({ label: t('modelType'), type: FormFieldType.Select, required: true, - options: [ - { label: 'chat', value: 'chat' }, - { label: 'embedding', value: 'embedding' }, - { label: 'image2text', value: 'image2text' }, - ], + options: buildModelTypeOptions(['chat', 'embedding', 'image2text']), defaultValue: 'embedding', validation: { message: t('modelTypeMessage'), diff --git a/web/src/pages/user-setting/setting-model/modal/bedrock-modal/index.tsx b/web/src/pages/user-setting/setting-model/modal/bedrock-modal/index.tsx index 664eb9a2f..c8ccaa3a2 100644 --- a/web/src/pages/user-setting/setting-model/modal/bedrock-modal/index.tsx +++ b/web/src/pages/user-setting/setting-model/modal/bedrock-modal/index.tsx @@ -6,6 +6,7 @@ import { Input } from '@/components/ui/input'; import { Modal } from '@/components/ui/modal/modal'; import { Segmented } from '@/components/ui/segmented'; import { useCommonTranslation, useTranslate } from '@/hooks/common-hooks'; +import { useBuildModelTypeOptions } from '@/hooks/logic-hooks/use-build-options'; import { IModalProps } from '@/interfaces/common'; import { IAddLlmRequestBody } from '@/interfaces/request/llm'; import { zodResolver } from '@hookform/resolvers/zod'; @@ -32,6 +33,7 @@ const BedrockModal = ({ }: IModalProps & { llmFactory: string }) => { const { t } = useTranslate('setting'); const { t: ct } = useCommonTranslation(); + const { buildModelTypeOptions } = useBuildModelTypeOptions(); const FormSchema = z .object({ @@ -160,10 +162,7 @@ const BedrockModal = ({ )} diff --git a/web/src/pages/user-setting/setting-model/modal/fish-audio-modal/index.tsx b/web/src/pages/user-setting/setting-model/modal/fish-audio-modal/index.tsx index 3ce52cef9..6962eeb7a 100644 --- a/web/src/pages/user-setting/setting-model/modal/fish-audio-modal/index.tsx +++ b/web/src/pages/user-setting/setting-model/modal/fish-audio-modal/index.tsx @@ -5,6 +5,7 @@ import { } from '@/components/dynamic-form'; import { Modal } from '@/components/ui/modal/modal'; import { useCommonTranslation, useTranslate } from '@/hooks/common-hooks'; +import { useBuildModelTypeOptions } from '@/hooks/logic-hooks/use-build-options'; import { IModalProps } from '@/interfaces/common'; import { IAddLlmRequestBody } from '@/interfaces/request/llm'; import { FieldValues } from 'react-hook-form'; @@ -19,6 +20,7 @@ const FishAudioModal = ({ }: IModalProps & { llmFactory: string }) => { const { t } = useTranslate('setting'); const { t: tc } = useCommonTranslation(); + const { buildModelTypeOptions } = useBuildModelTypeOptions(); const fields: FormFieldConfig[] = [ { @@ -26,7 +28,7 @@ const FishAudioModal = ({ label: t('modelType'), type: FormFieldType.Select, required: true, - options: [{ label: 'tts', value: 'tts' }], + options: buildModelTypeOptions(['tts']), defaultValue: 'tts', validation: { message: t('modelTypeMessage') }, }, diff --git a/web/src/pages/user-setting/setting-model/modal/google-modal/index.tsx b/web/src/pages/user-setting/setting-model/modal/google-modal/index.tsx index 4dbbe0732..75e52d8ab 100644 --- a/web/src/pages/user-setting/setting-model/modal/google-modal/index.tsx +++ b/web/src/pages/user-setting/setting-model/modal/google-modal/index.tsx @@ -5,6 +5,7 @@ import { } from '@/components/dynamic-form'; import { Modal } from '@/components/ui/modal/modal'; import { useCommonTranslation, useTranslate } from '@/hooks/common-hooks'; +import { useBuildModelTypeOptions } from '@/hooks/logic-hooks/use-build-options'; import { IModalProps } from '@/interfaces/common'; import { IAddLlmRequestBody } from '@/interfaces/request/llm'; import { FieldValues } from 'react-hook-form'; @@ -19,6 +20,7 @@ const GoogleModal = ({ }: IModalProps & { llmFactory: string }) => { const { t } = useTranslate('setting'); const { t: tc } = useCommonTranslation(); + const { buildModelTypeOptions } = useBuildModelTypeOptions(); const fields: FormFieldConfig[] = [ { @@ -26,10 +28,7 @@ const GoogleModal = ({ label: t('modelType'), type: FormFieldType.Select, required: true, - options: [ - { label: 'chat', value: 'chat' }, - { label: 'image2text', value: 'image2text' }, - ], + options: buildModelTypeOptions(['chat', 'image2text']), defaultValue: 'chat', validation: { message: t('modelTypeMessage'), diff --git a/web/src/pages/user-setting/setting-model/modal/next-tencent-modal/index.tsx b/web/src/pages/user-setting/setting-model/modal/next-tencent-modal/index.tsx index 5d0329e8d..2bc80a1a0 100644 --- a/web/src/pages/user-setting/setting-model/modal/next-tencent-modal/index.tsx +++ b/web/src/pages/user-setting/setting-model/modal/next-tencent-modal/index.tsx @@ -5,6 +5,7 @@ import { } from '@/components/dynamic-form'; import { Modal } from '@/components/ui/modal/modal'; import { useCommonTranslation, useTranslate } from '@/hooks/common-hooks'; +import { useBuildModelTypeOptions } from '@/hooks/logic-hooks/use-build-options'; import { IModalProps } from '@/interfaces/common'; import { IAddLlmRequestBody } from '@/interfaces/request/llm'; import { FieldValues } from 'react-hook-form'; @@ -21,6 +22,7 @@ const TencentCloudModal = ({ }) => { const { t } = useTranslate('setting'); const { t: tc } = useCommonTranslation(); + const { buildModelTypeOptions } = useBuildModelTypeOptions(); const fields: FormFieldConfig[] = [ { @@ -28,7 +30,7 @@ const TencentCloudModal = ({ label: t('modelType'), type: FormFieldType.Select, required: true, - options: [{ label: 'speech2text', value: 'speech2text' }], + options: buildModelTypeOptions(['speech2text']), defaultValue: 'speech2text', validation: { message: t('modelTypeMessage'), diff --git a/web/src/pages/user-setting/setting-model/modal/ollama-modal/index.tsx b/web/src/pages/user-setting/setting-model/modal/ollama-modal/index.tsx index bdce2e15c..8b0fe00f1 100644 --- a/web/src/pages/user-setting/setting-model/modal/ollama-modal/index.tsx +++ b/web/src/pages/user-setting/setting-model/modal/ollama-modal/index.tsx @@ -6,6 +6,7 @@ import { import { Modal } from '@/components/ui/modal/modal'; import { LLMFactory } from '@/constants/llm'; import { useCommonTranslation, useTranslate } from '@/hooks/common-hooks'; +import { useBuildModelTypeOptions } from '@/hooks/logic-hooks/use-build-options'; import { IModalProps } from '@/interfaces/common'; import { IAddLlmRequestBody } from '@/interfaces/request/llm'; import { useMemo } from 'react'; @@ -33,49 +34,6 @@ const llmFactoryToUrlMap: Partial> = { [LLMFactory.TokenPony]: 'https://docs.tokenpony.cn/#/', }; -const optionsMap: Partial< - Record -> & { - Default: { label: string; value: string }[]; -} = { - [LLMFactory.HuggingFace]: [ - { label: 'embedding', value: 'embedding' }, - { label: 'chat', value: 'chat' }, - { label: 'rerank', value: 'rerank' }, - ], - [LLMFactory.LMStudio]: [ - { label: 'chat', value: 'chat' }, - { label: 'embedding', value: 'embedding' }, - { label: 'image2text', value: 'image2text' }, - ], - [LLMFactory.Xinference]: [ - { label: 'chat', value: 'chat' }, - { label: 'embedding', value: 'embedding' }, - { label: 'rerank', value: 'rerank' }, - { label: 'image2text', value: 'image2text' }, - { label: 'sequence2text', value: 'speech2text' }, - { label: 'tts', value: 'tts' }, - ], - [LLMFactory.ModelScope]: [{ label: 'chat', value: 'chat' }], - [LLMFactory.GPUStack]: [ - { label: 'chat', value: 'chat' }, - { label: 'embedding', value: 'embedding' }, - { label: 'rerank', value: 'rerank' }, - { label: 'sequence2text', value: 'speech2text' }, - { label: 'tts', value: 'tts' }, - ], - [LLMFactory.OpenRouter]: [ - { label: 'chat', value: 'chat' }, - { label: 'image2text', value: 'image2text' }, - ], - Default: [ - { label: 'chat', value: 'chat' }, - { label: 'embedding', value: 'embedding' }, - { label: 'rerank', value: 'rerank' }, - { label: 'image2text', value: 'image2text' }, - ], -}; - const OllamaModal = ({ visible, hideModal, @@ -90,6 +48,47 @@ const OllamaModal = ({ }) => { const { t } = useTranslate('setting'); const { t: tc } = useCommonTranslation(); + const { buildModelTypeOptions } = useBuildModelTypeOptions(); + + const optionsMap: Partial< + Record + > & { + Default: { label: string; value: string }[]; + } = { + [LLMFactory.HuggingFace]: buildModelTypeOptions([ + 'embedding', + 'chat', + 'rerank', + ]), + [LLMFactory.LMStudio]: buildModelTypeOptions([ + 'chat', + 'embedding', + 'image2text', + ]), + [LLMFactory.Xinference]: buildModelTypeOptions([ + 'chat', + 'embedding', + 'rerank', + 'image2text', + 'speech2text', + 'tts', + ]), + [LLMFactory.ModelScope]: buildModelTypeOptions(['chat']), + [LLMFactory.GPUStack]: buildModelTypeOptions([ + 'chat', + 'embedding', + 'rerank', + 'speech2text', + 'tts', + ]), + [LLMFactory.OpenRouter]: buildModelTypeOptions(['chat', 'image2text']), + Default: buildModelTypeOptions([ + 'chat', + 'embedding', + 'rerank', + 'image2text', + ]), + }; const url = llmFactoryToUrlMap[llmFactory as LLMFactory] || diff --git a/web/src/pages/user-setting/setting-model/modal/spark-modal/index.tsx b/web/src/pages/user-setting/setting-model/modal/spark-modal/index.tsx index bac3c3b1d..9f119d2de 100644 --- a/web/src/pages/user-setting/setting-model/modal/spark-modal/index.tsx +++ b/web/src/pages/user-setting/setting-model/modal/spark-modal/index.tsx @@ -5,6 +5,7 @@ import { } from '@/components/dynamic-form'; import { Modal } from '@/components/ui/modal/modal'; import { useCommonTranslation, useTranslate } from '@/hooks/common-hooks'; +import { useBuildModelTypeOptions } from '@/hooks/logic-hooks/use-build-options'; import { IModalProps } from '@/interfaces/common'; import { IAddLlmRequestBody } from '@/interfaces/request/llm'; import omit from 'lodash/omit'; @@ -20,6 +21,7 @@ const SparkModal = ({ }: IModalProps & { llmFactory: string }) => { const { t } = useTranslate('setting'); const { t: tc } = useCommonTranslation(); + const { buildModelTypeOptions } = useBuildModelTypeOptions(); const fields: FormFieldConfig[] = [ { @@ -27,10 +29,7 @@ const SparkModal = ({ label: t('modelType'), type: FormFieldType.Select, required: true, - options: [ - { label: 'chat', value: 'chat' }, - { label: 'tts', value: 'tts' }, - ], + options: buildModelTypeOptions(['chat', 'tts']), defaultValue: 'chat', validation: { message: t('modelTypeMessage'), diff --git a/web/src/pages/user-setting/setting-model/modal/volcengine-modal/index.tsx b/web/src/pages/user-setting/setting-model/modal/volcengine-modal/index.tsx index 388fbe5d6..cd8646d32 100644 --- a/web/src/pages/user-setting/setting-model/modal/volcengine-modal/index.tsx +++ b/web/src/pages/user-setting/setting-model/modal/volcengine-modal/index.tsx @@ -5,6 +5,7 @@ import { } from '@/components/dynamic-form'; import { Modal } from '@/components/ui/modal/modal'; import { useCommonTranslation, useTranslate } from '@/hooks/common-hooks'; +import { useBuildModelTypeOptions } from '@/hooks/logic-hooks/use-build-options'; import { IModalProps } from '@/interfaces/common'; import { IAddLlmRequestBody } from '@/interfaces/request/llm'; import { FieldValues } from 'react-hook-form'; @@ -24,6 +25,7 @@ const VolcEngineModal = ({ }: IModalProps & { llmFactory: string }) => { const { t } = useTranslate('setting'); const { t: tc } = useCommonTranslation(); + const { buildModelTypeOptions } = useBuildModelTypeOptions(); const fields: FormFieldConfig[] = [ { @@ -31,11 +33,7 @@ const VolcEngineModal = ({ label: t('modelType'), type: FormFieldType.Select, required: true, - options: [ - { label: 'chat', value: 'chat' }, - { label: 'embedding', value: 'embedding' }, - { label: 'image2text', value: 'image2text' }, - ], + options: buildModelTypeOptions(['chat', 'embedding', 'image2text']), defaultValue: 'chat', }, { diff --git a/web/src/pages/user-setting/setting-model/modal/yiyan-modal/index.tsx b/web/src/pages/user-setting/setting-model/modal/yiyan-modal/index.tsx index 511f96077..ed05845cf 100644 --- a/web/src/pages/user-setting/setting-model/modal/yiyan-modal/index.tsx +++ b/web/src/pages/user-setting/setting-model/modal/yiyan-modal/index.tsx @@ -5,6 +5,7 @@ import { } from '@/components/dynamic-form'; import { Modal } from '@/components/ui/modal/modal'; import { useCommonTranslation, useTranslate } from '@/hooks/common-hooks'; +import { useBuildModelTypeOptions } from '@/hooks/logic-hooks/use-build-options'; import { IModalProps } from '@/interfaces/common'; import { IAddLlmRequestBody } from '@/interfaces/request/llm'; import { FieldValues } from 'react-hook-form'; @@ -19,6 +20,7 @@ const YiyanModal = ({ }: IModalProps & { llmFactory: string }) => { const { t } = useTranslate('setting'); const { t: tc } = useCommonTranslation(); + const { buildModelTypeOptions } = useBuildModelTypeOptions(); const fields: FormFieldConfig[] = [ { @@ -26,11 +28,7 @@ const YiyanModal = ({ label: t('modelType'), type: FormFieldType.Select, required: true, - options: [ - { label: 'chat', value: 'chat' }, - { label: 'embedding', value: 'embedding' }, - { label: 'rerank', value: 'rerank' }, - ], + options: buildModelTypeOptions(['chat', 'embedding', 'rerank']), defaultValue: 'chat', }, {