diff --git a/pkg/core/migrations/m028_aliyun_requester_config.py b/pkg/core/migrations/m028_aliyun_requester_config.py new file mode 100644 index 00000000..f28bc04f --- /dev/null +++ b/pkg/core/migrations/m028_aliyun_requester_config.py @@ -0,0 +1,27 @@ +from __future__ import annotations + +from .. import migration + + +@migration.migration_class("bailian-requester-config", 28) +class BailianRequesterConfigMigration(migration.Migration): + """迁移""" + + async def need_migrate(self) -> bool: + """判断当前环境是否需要运行此迁移""" + + return 'bailian-chat-completions' not in self.ap.provider_cfg.data['requester'] + + async def run(self): + """执行迁移""" + self.ap.provider_cfg.data['keys']['bailian'] = [ + "sk-xxxxxxx" + ] + + self.ap.provider_cfg.data['requester']['bailian-chat-completions'] = { + "base-url": "https://dashscope.aliyuncs.com/compatible-mode/v1", + "args": {}, + "timeout": 120 + } + + await self.ap.provider_cfg.dump_config() diff --git a/pkg/core/stages/migrate.py b/pkg/core/stages/migrate.py index a1983f0b..6d59065b 100644 --- a/pkg/core/stages/migrate.py +++ b/pkg/core/stages/migrate.py @@ -9,7 +9,8 @@ from ..migrations import m005_deepseek_cfg_completion, m006_vision_config, m007_ from ..migrations import m010_ollama_requester_config, m011_command_prefix_config, m012_runner_config, m013_http_api_config, m014_force_delay_config from ..migrations import m015_gitee_ai_config, m016_dify_service_api, m017_dify_api_timeout_params, m018_xai_config, m019_zhipuai_config from ..migrations import m020_wecom_config, m021_lark_config, m022_lmstudio_config, m023_siliconflow_config, m024_discord_config, m025_gewechat_config -from ..migrations import m026_qqofficial_config, m027_wx_official_account_config +from ..migrations import m026_qqofficial_config, m027_wx_official_account_config, m028_aliyun_requester_config + @stage.stage_class("MigrationStage") class MigrationStage(stage.BootingStage): diff --git a/pkg/provider/modelmgr/modelmgr.py b/pkg/provider/modelmgr/modelmgr.py index 33a65ff3..489a322f 100644 --- a/pkg/provider/modelmgr/modelmgr.py +++ b/pkg/provider/modelmgr/modelmgr.py @@ -6,7 +6,7 @@ from . import entities, requester from ...core import app from . import token -from .requesters import chatcmpl, anthropicmsgs, moonshotchatcmpl, deepseekchatcmpl, ollamachat, giteeaichatcmpl, xaichatcmpl, zhipuaichatcmpl, lmstudiochatcmpl, siliconflowchatcmpl +from .requesters import bailianchatcmpl, chatcmpl, anthropicmsgs, moonshotchatcmpl, deepseekchatcmpl, ollamachat, giteeaichatcmpl, xaichatcmpl, zhipuaichatcmpl, lmstudiochatcmpl, siliconflowchatcmpl FETCH_MODEL_LIST_URL = "https://api.qchatgpt.rockchin.top/api/v2/fetch/model_list" diff --git a/pkg/provider/modelmgr/requesters/bailianchatcmpl.py b/pkg/provider/modelmgr/requesters/bailianchatcmpl.py new file mode 100644 index 00000000..cce003bd --- /dev/null +++ b/pkg/provider/modelmgr/requesters/bailianchatcmpl.py @@ -0,0 +1,21 @@ +from __future__ import annotations + +import openai + +from . import chatcmpl +from .. import requester +from ....core import app + + +@requester.requester_class("bailian-chat-completions") +class BailianChatCompletions(chatcmpl.OpenAIChatCompletions): + """阿里云百炼大模型平台 ChatCompletion API 请求器""" + + client: openai.AsyncClient + + requester_cfg: dict + + def __init__(self, ap: app.Application): + self.ap = ap + + self.requester_cfg = self.ap.provider_cfg.data['requester']['bailian-chat-completions'] diff --git a/templates/provider.json b/templates/provider.json index 5ab5cd64..551c7d88 100644 --- a/templates/provider.json +++ b/templates/provider.json @@ -25,6 +25,9 @@ ], "siliconflow": [ "xxxxxxx" + ], + "bailian": [ + "sk-xxxxxxx" ] }, "requester": { @@ -79,12 +82,17 @@ "base-url": "https://api.siliconflow.cn/v1", "args": {}, "timeout": 120 + }, + "bailian-chat-completions": { + "args": {}, + "base-url": "https://dashscope.aliyuncs.com/compatible-mode/v1", + "timeout": 120 } }, "model": "gpt-4o", "prompt-mode": "normal", "prompt": { - "default": "" + "default": "" }, "runner": "local-agent", "dify-service-api": { diff --git a/templates/schema/provider.json b/templates/schema/provider.json index bd2084b8..e6f806c5 100644 --- a/templates/schema/provider.json +++ b/templates/schema/provider.json @@ -82,6 +82,14 @@ "type": "string" }, "default": [] + }, + "bailian": { + "type": "array", + "title": "阿里云百炼大模型平台 API 密钥", + "items": { + "type": "string" + }, + "default": [] } } }, @@ -288,6 +296,26 @@ "default": 120 } } + }, + "bailian-chat-completions": { + "type": "object", + "title": "阿里云百炼大模型平台 API 请求配置", + "description": "仅可编辑 URL 和 超时时间,额外请求参数不支持可视化编辑,请到编辑器编辑", + "properties": { + "base-url": { + "type": "string", + "title": "API URL" + }, + "args": { + "type": "object", + "default": {} + }, + "timeout": { + "type": "number", + "title": "API 请求超时时间", + "default": 120 + } + } } } },