Skip to content

Commit 6e760ef

Browse files
feat: Add Azure OpenAI Support
1 parent 07acbd0 commit 6e760ef

File tree

2 files changed

+51
-2
lines changed

2 files changed

+51
-2
lines changed

backend/apps/ai_model/model_factory.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from common.core.db import engine
1313
from common.utils.utils import prepare_model_arg
1414
from langchain_community.llms import VLLMOpenAI
15-
15+
from langchain_openai import AzureChatOpenAI
1616
# from langchain_community.llms import Tongyi, VLLM
1717

1818
class LLMConfig(BaseModel):
@@ -69,6 +69,24 @@ def _init_llm(self) -> VLLMOpenAI:
6969
streaming=True,
7070
**self.config.additional_params,
7171
)
72+
73+
class OpenAIAzureLLM(BaseLLM):
74+
def _init_llm(self) -> AzureChatOpenAI:
75+
api_version = self.config.additional_params.get("api_version")
76+
deployment_name = self.config.additional_params.get("deployment_name")
77+
if api_version:
78+
self.config.additional_params.pop("api_version")
79+
if deployment_name:
80+
self.config.additional_params.pop("deployment_name")
81+
return AzureChatOpenAI(
82+
azure_endpoint=self.config.api_base_url,
83+
api_key=self.config.api_key or 'Empty',
84+
model_name=self.config.model_name,
85+
api_version=api_version,
86+
deployment_name=deployment_name,
87+
streaming=True,
88+
**self.config.additional_params,
89+
)
7290
class OpenAILLM(BaseLLM):
7391
def _init_llm(self) -> BaseChatModel:
7492
return BaseChatOpenAI(
@@ -89,7 +107,8 @@ class LLMFactory:
89107
_llm_types: Dict[str, Type[BaseLLM]] = {
90108
"openai": OpenAILLM,
91109
"tongyi": OpenAILLM,
92-
"vllm": OpenAIvLLM
110+
"vllm": OpenAIvLLM,
111+
"azure": OpenAIAzureLLM,
93112
}
94113

95114
@classmethod

frontend/src/entity/supplier.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import icon_txhy_colorful from '@/assets/model/icon_txhy_colorful.png'
1010
import icon_hsyq_colorful from '@/assets/model/icon_hsyq_colorful.png'
1111
// import icon_vllm_colorful from '@/assets/model/icon_vllm_colorful.png'
1212
import icon_common_openai from '@/assets/model/icon_common_openai.png'
13+
import icon_azure_openAI_colorful from '@/assets/model/icon_Azure_OpenAI_colorful.png'
1314

1415
type ModelArg = { key: string; val?: string | number; type: string; range?: string }
1516
type ModelOption = { name: string; api_domain?: string; args?: ModelArg[] }
@@ -281,6 +282,35 @@ export const supplierList: Array<{
281282
},
282283
},
283284
}, */
285+
{
286+
id: 12,
287+
name: 'Azure OpenAI',
288+
icon: icon_azure_openAI_colorful,
289+
type: 'azure',
290+
is_private: true,
291+
model_config: {
292+
0: {
293+
api_domain: 'https://{your resource name}.openai.azure.cn/',
294+
common_args: [{ key: 'temperature', val: 0.6, type: 'number', range: '[0, 1]' }],
295+
model_options: [
296+
{
297+
name: 'Azure OpenAI',
298+
args: [
299+
{ key: 'api_version', val: '2024-02-15-preview', type: 'string' },
300+
{ key: 'deployment_name', val: '', type: 'string' },
301+
],
302+
},
303+
{
304+
name: 'gpt-4',
305+
args: [
306+
{ key: 'api_version', val: '2024-02-15-preview', type: 'string' },
307+
{ key: 'deployment_name', val: '', type: 'string' },
308+
],
309+
},
310+
],
311+
},
312+
},
313+
},
284314
{
285315
id: 15,
286316
name: '通用OpenAI',

0 commit comments

Comments
 (0)