diff --git a/backend/apps/ai_model/model_factory.py b/backend/apps/ai_model/model_factory.py index 243c91e0..e0186e9f 100644 --- a/backend/apps/ai_model/model_factory.py +++ b/backend/apps/ai_model/model_factory.py @@ -12,7 +12,7 @@ from apps.system.models.system_model import AiModelDetail from common.core.db import engine from common.utils.utils import prepare_model_arg from langchain_community.llms import VLLMOpenAI - +from langchain_openai import AzureChatOpenAI # from langchain_community.llms import Tongyi, VLLM class LLMConfig(BaseModel): @@ -69,6 +69,24 @@ class OpenAIvLLM(BaseLLM): streaming=True, **self.config.additional_params, ) + +class OpenAIAzureLLM(BaseLLM): + def _init_llm(self) -> AzureChatOpenAI: + api_version = self.config.additional_params.get("api_version") + deployment_name = self.config.additional_params.get("deployment_name") + if api_version: + self.config.additional_params.pop("api_version") + if deployment_name: + self.config.additional_params.pop("deployment_name") + return AzureChatOpenAI( + azure_endpoint=self.config.api_base_url, + api_key=self.config.api_key or 'Empty', + model_name=self.config.model_name, + api_version=api_version, + deployment_name=deployment_name, + streaming=True, + **self.config.additional_params, + ) class OpenAILLM(BaseLLM): def _init_llm(self) -> BaseChatModel: return BaseChatOpenAI( @@ -89,7 +107,8 @@ class LLMFactory: _llm_types: Dict[str, Type[BaseLLM]] = { "openai": OpenAILLM, "tongyi": OpenAILLM, - "vllm": OpenAIvLLM + "vllm": OpenAIvLLM, + "azure": OpenAIAzureLLM, } @classmethod diff --git a/frontend/src/assets/model/icon_common_openai.png b/frontend/src/assets/model/icon_common_openai.png new file mode 100644 index 00000000..809fa7cc Binary files /dev/null and b/frontend/src/assets/model/icon_common_openai.png differ diff --git a/frontend/src/entity/supplier.ts b/frontend/src/entity/supplier.ts index 2e69c776..ef90713d 100644 --- a/frontend/src/entity/supplier.ts +++ b/frontend/src/entity/supplier.ts @@ -8,7 +8,9 @@ import icon_openai_colorful from '@/assets/model/icon_openai_colorful.png' import icon_kimi_colorful from '@/assets/model/icon_kimi_colorful.png' import icon_txhy_colorful from '@/assets/model/icon_txhy_colorful.png' import icon_hsyq_colorful from '@/assets/model/icon_hsyq_colorful.png' -import icon_vllm_colorful from '@/assets/model/icon_vllm_colorful.png' +// import icon_vllm_colorful from '@/assets/model/icon_vllm_colorful.png' +import icon_common_openai from '@/assets/model/icon_common_openai.png' +import icon_azure_openAI_colorful from '@/assets/model/icon_Azure_OpenAI_colorful.png' type ModelArg = { key: string; val?: string | number; type: string; range?: string } type ModelOption = { name: string; api_domain?: string; args?: ModelArg[] } @@ -266,7 +268,7 @@ export const supplierList: Array<{ }, }, }, - { + /* { id: 11, name: 'vLLM', icon: icon_vllm_colorful, @@ -279,6 +281,64 @@ export const supplierList: Array<{ model_options: [], }, }, + }, */ + { + id: 12, + name: 'Azure OpenAI', + icon: icon_azure_openAI_colorful, + type: 'azure', + is_private: true, + model_config: { + 0: { + api_domain: 'https://{your resource name}.openai.azure.cn/', + common_args: [{ key: 'temperature', val: 0.6, type: 'number', range: '[0, 1]' }], + model_options: [ + { + name: 'Azure OpenAI', + args: [ + { key: 'api_version', val: '2024-02-15-preview', type: 'string' }, + { key: 'deployment_name', val: '', type: 'string' }, + ], + }, + { + name: 'gpt-4', + args: [ + { key: 'api_version', val: '2024-02-15-preview', type: 'string' }, + { key: 'deployment_name', val: '', type: 'string' }, + ], + }, + ], + }, + }, + }, + { + id: 15, + name: '通用OpenAI', + icon: icon_common_openai, + is_private: true, + model_config: { + 0: { + api_domain: 'http://127.0.0.1:8000/v1', + common_args: [{ key: 'temperature', val: 0.6, type: 'number', range: '[0, 1]' }], + model_options: [ + { name: 'gpt-4.1' }, + { name: 'gpt-4.1-mini' }, + { name: 'gpt-4.1-nano' }, + { name: 'gpt-4o' }, + { name: 'gpt-4o-mini' }, + { name: 'chatgpt-4o' }, + { name: 'o4-mini' }, + { name: 'o4-mini-deep-research' }, + { name: 'o3' }, + { name: 'o3-pro' }, + { name: 'o3-mini' }, + { name: 'o3-deep-research' }, + { name: 'o1' }, + { name: 'o1-pro' }, + { name: 'o1-mini' }, + ], + }, + }, }, ]