From e1cd9aef8ff84876e1ca7d6f25d077d07ece0f89 Mon Sep 17 00:00:00 2001 From: xielong Date: Wed, 29 May 2024 14:46:04 +0800 Subject: [PATCH] feat: support baichuan3 turbo, baichuan3 turbo 128k, and baichuan4 (#4762) --- .../baichuan/llm/baichuan3-turbo-128k.yaml | 45 +++++++++++++++++++ .../baichuan/llm/baichuan3-turbo.yaml | 45 +++++++++++++++++++ .../baichuan/llm/baichuan4.yaml | 45 +++++++++++++++++++ .../baichuan/llm/baichuan_turbo.py | 12 +++-- 4 files changed, 144 insertions(+), 3 deletions(-) create mode 100644 api/core/model_runtime/model_providers/baichuan/llm/baichuan3-turbo-128k.yaml create mode 100644 api/core/model_runtime/model_providers/baichuan/llm/baichuan3-turbo.yaml create mode 100644 api/core/model_runtime/model_providers/baichuan/llm/baichuan4.yaml diff --git a/api/core/model_runtime/model_providers/baichuan/llm/baichuan3-turbo-128k.yaml b/api/core/model_runtime/model_providers/baichuan/llm/baichuan3-turbo-128k.yaml new file mode 100644 index 000000000..bf72e8229 --- /dev/null +++ b/api/core/model_runtime/model_providers/baichuan/llm/baichuan3-turbo-128k.yaml @@ -0,0 +1,45 @@ +model: baichuan3-turbo-128k +label: + en_US: Baichuan3-Turbo-128k +model_type: llm +features: + - agent-thought +model_properties: + mode: chat + context_size: 128000 +parameter_rules: + - name: temperature + use_template: temperature + - name: top_p + use_template: top_p + - name: top_k + label: + zh_Hans: 取样数量 + en_US: Top k + type: int + help: + zh_Hans: 仅从每个后续标记的前 K 个选项中采样。 + en_US: Only sample from the top K options for each subsequent token. + required: false + - name: max_tokens + use_template: max_tokens + required: true + default: 8000 + min: 1 + max: 128000 + - name: presence_penalty + use_template: presence_penalty + - name: frequency_penalty + use_template: frequency_penalty + default: 1 + min: 1 + max: 2 + - name: with_search_enhance + label: + zh_Hans: 搜索增强 + en_US: Search Enhance + type: boolean + help: + zh_Hans: 允许模型自行进行外部搜索,以增强生成结果。 + en_US: Allow the model to perform external search to enhance the generation results. + required: false diff --git a/api/core/model_runtime/model_providers/baichuan/llm/baichuan3-turbo.yaml b/api/core/model_runtime/model_providers/baichuan/llm/baichuan3-turbo.yaml new file mode 100644 index 000000000..85882519b --- /dev/null +++ b/api/core/model_runtime/model_providers/baichuan/llm/baichuan3-turbo.yaml @@ -0,0 +1,45 @@ +model: baichuan3-turbo +label: + en_US: Baichuan3-Turbo +model_type: llm +features: + - agent-thought +model_properties: + mode: chat + context_size: 32000 +parameter_rules: + - name: temperature + use_template: temperature + - name: top_p + use_template: top_p + - name: top_k + label: + zh_Hans: 取样数量 + en_US: Top k + type: int + help: + zh_Hans: 仅从每个后续标记的前 K 个选项中采样。 + en_US: Only sample from the top K options for each subsequent token. + required: false + - name: max_tokens + use_template: max_tokens + required: true + default: 8000 + min: 1 + max: 32000 + - name: presence_penalty + use_template: presence_penalty + - name: frequency_penalty + use_template: frequency_penalty + default: 1 + min: 1 + max: 2 + - name: with_search_enhance + label: + zh_Hans: 搜索增强 + en_US: Search Enhance + type: boolean + help: + zh_Hans: 允许模型自行进行外部搜索,以增强生成结果。 + en_US: Allow the model to perform external search to enhance the generation results. + required: false diff --git a/api/core/model_runtime/model_providers/baichuan/llm/baichuan4.yaml b/api/core/model_runtime/model_providers/baichuan/llm/baichuan4.yaml new file mode 100644 index 000000000..f8c656608 --- /dev/null +++ b/api/core/model_runtime/model_providers/baichuan/llm/baichuan4.yaml @@ -0,0 +1,45 @@ +model: baichuan4 +label: + en_US: Baichuan4 +model_type: llm +features: + - agent-thought +model_properties: + mode: chat + context_size: 32000 +parameter_rules: + - name: temperature + use_template: temperature + - name: top_p + use_template: top_p + - name: top_k + label: + zh_Hans: 取样数量 + en_US: Top k + type: int + help: + zh_Hans: 仅从每个后续标记的前 K 个选项中采样。 + en_US: Only sample from the top K options for each subsequent token. + required: false + - name: max_tokens + use_template: max_tokens + required: true + default: 8000 + min: 1 + max: 32000 + - name: presence_penalty + use_template: presence_penalty + - name: frequency_penalty + use_template: frequency_penalty + default: 1 + min: 1 + max: 2 + - name: with_search_enhance + label: + zh_Hans: 搜索增强 + en_US: Search Enhance + type: boolean + help: + zh_Hans: 允许模型自行进行外部搜索,以增强生成结果。 + en_US: Allow the model to perform external search to enhance the generation results. + required: false diff --git a/api/core/model_runtime/model_providers/baichuan/llm/baichuan_turbo.py b/api/core/model_runtime/model_providers/baichuan/llm/baichuan_turbo.py index d524ee84b..ad7cf4096 100644 --- a/api/core/model_runtime/model_providers/baichuan/llm/baichuan_turbo.py +++ b/api/core/model_runtime/model_providers/baichuan/llm/baichuan_turbo.py @@ -51,6 +51,9 @@ class BaichuanModel: 'baichuan2-turbo': 'Baichuan2-Turbo', 'baichuan2-turbo-192k': 'Baichuan2-Turbo-192k', 'baichuan2-53b': 'Baichuan2-53B', + 'baichuan3-turbo': 'Baichuan3-Turbo', + 'baichuan3-turbo-128k': 'Baichuan3-Turbo-128k', + 'baichuan4': 'Baichuan4', }[model] def _handle_chat_generate_response(self, response) -> BaichuanMessage: @@ -110,7 +113,8 @@ class BaichuanModel: def _build_parameters(self, model: str, stream: bool, messages: list[BaichuanMessage], parameters: dict[str, Any]) \ -> dict[str, Any]: - if model == 'baichuan2-turbo' or model == 'baichuan2-turbo-192k' or model == 'baichuan2-53b': + if (model == 'baichuan2-turbo' or model == 'baichuan2-turbo-192k' or model == 'baichuan2-53b' + or model == 'baichuan3-turbo' or model == 'baichuan3-turbo-128k' or model == 'baichuan4'): prompt_messages = [] for message in messages: if message.role == BaichuanMessage.Role.USER.value or message.role == BaichuanMessage.Role._SYSTEM.value: @@ -143,7 +147,8 @@ class BaichuanModel: raise BadRequestError(f"Unknown model: {model}") def _build_headers(self, model: str, data: dict[str, Any]) -> dict[str, Any]: - if model == 'baichuan2-turbo' or model == 'baichuan2-turbo-192k' or model == 'baichuan2-53b': + if (model == 'baichuan2-turbo' or model == 'baichuan2-turbo-192k' or model == 'baichuan2-53b' + or model == 'baichuan3-turbo' or model == 'baichuan3-turbo-128k' or model == 'baichuan4'): # there is no secret key for turbo api return { 'Content-Type': 'application/json', @@ -160,7 +165,8 @@ class BaichuanModel: parameters: dict[str, Any], timeout: int) \ -> Union[Generator, BaichuanMessage]: - if model == 'baichuan2-turbo' or model == 'baichuan2-turbo-192k' or model == 'baichuan2-53b': + if (model == 'baichuan2-turbo' or model == 'baichuan2-turbo-192k' or model == 'baichuan2-53b' + or model == 'baichuan3-turbo' or model == 'baichuan3-turbo-128k' or model == 'baichuan4'): api_base = 'https://api.baichuan-ai.com/v1/chat/completions' else: raise BadRequestError(f"Unknown model: {model}")