From e52448b84b7452408dbfd03a9b07dd2cb1b8f63d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=86=E8=90=8C=E9=97=B7=E6=B2=B9=E7=93=B6?= <253605712@qq.com> Date: Thu, 14 Mar 2024 09:14:27 +0800 Subject: [PATCH] feat:add api-version selection for azure openai APIs (#2821) --- .../model_providers/azure_openai/_common.py | 3 ++- .../model_providers/azure_openai/_constant.py | 1 - .../azure_openai/azure_openai.yaml | 16 ++++++++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/api/core/model_runtime/model_providers/azure_openai/_common.py b/api/core/model_runtime/model_providers/azure_openai/_common.py index b65138252b5c18..31c788d226db34 100644 --- a/api/core/model_runtime/model_providers/azure_openai/_common.py +++ b/api/core/model_runtime/model_providers/azure_openai/_common.py @@ -15,10 +15,11 @@ class _CommonAzureOpenAI: @staticmethod def _to_credential_kwargs(credentials: dict) -> dict: + api_version = credentials.get('openai_api_version', AZURE_OPENAI_API_VERSION) credentials_kwargs = { "api_key": credentials['openai_api_key'], "azure_endpoint": credentials['openai_api_base'], - "api_version": AZURE_OPENAI_API_VERSION, + "api_version": api_version, "timeout": Timeout(315.0, read=300.0, write=10.0, connect=5.0), "max_retries": 1, } diff --git a/api/core/model_runtime/model_providers/azure_openai/_constant.py b/api/core/model_runtime/model_providers/azure_openai/_constant.py index dda02588126b56..4aa767fa1de180 100644 --- a/api/core/model_runtime/model_providers/azure_openai/_constant.py +++ b/api/core/model_runtime/model_providers/azure_openai/_constant.py @@ -16,7 +16,6 @@ AZURE_OPENAI_API_VERSION = '2024-02-15-preview' - def _get_max_tokens(default: int, min_val: int, max_val: int) -> ParameterRule: rule = ParameterRule( name='max_tokens', diff --git a/api/core/model_runtime/model_providers/azure_openai/azure_openai.yaml b/api/core/model_runtime/model_providers/azure_openai/azure_openai.yaml index 58800ddee2c8a9..224f2a08a16f50 100644 --- a/api/core/model_runtime/model_providers/azure_openai/azure_openai.yaml +++ b/api/core/model_runtime/model_providers/azure_openai/azure_openai.yaml @@ -46,6 +46,22 @@ model_credential_schema: placeholder: zh_Hans: 在此输入您的 API Key en_US: Enter your API key here + - variable: openai_api_version + label: + zh_Hans: API 版本 + en_US: API Version + type: select + required: true + options: + - label: + en_US: 2024-02-15-preview + value: 2024-02-15-preview + - label: + en_US: 2023-12-01-preview + value: 2023-12-01-preview + placeholder: + zh_Hans: 在此选择您的 API 版本 + en_US: Select your API Version here - variable: base_model_name label: en_US: Base Model