feat: Add Azure OpenAI Support

This commit is contained in:
fit2cloud-chenyw
2025-08-26 12:31:45 +08:00
parent 07acbd09a3
commit 6e760ef69b
2 changed files with 51 additions and 2 deletions
+21 -2
View File
@@ -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
+30
View File
@@ -10,6 +10,7 @@ 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_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[] }
@@ -281,6 +282,35 @@ export const supplierList: Array<{
},
},
}, */
{
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',