From 32bd194bfc5d3fccbf3cb6115f9f4729a4c1a4da Mon Sep 17 00:00:00 2001 From: RockChinQ <1010553892@qq.com> Date: Mon, 18 Mar 2024 21:04:09 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20anthropic=20=E7=9A=84=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E8=A1=A5=E5=85=A8=E8=BF=81=E7=A7=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../m3_anthropic_requester_cfg_completion.py | 32 +++++++++++++++++++ pkg/core/stages/migrate.py | 2 +- 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 pkg/config/migrations/m3_anthropic_requester_cfg_completion.py diff --git a/pkg/config/migrations/m3_anthropic_requester_cfg_completion.py b/pkg/config/migrations/m3_anthropic_requester_cfg_completion.py new file mode 100644 index 00000000..82ad2a7a --- /dev/null +++ b/pkg/config/migrations/m3_anthropic_requester_cfg_completion.py @@ -0,0 +1,32 @@ +from __future__ import annotations + +from .. import migration + + +@migration.migration_class("anthropic-requester-config-completion", 3) +class AnthropicRequesterConfigCompletionMigration(migration.Migration): + """OpenAI配置迁移 + """ + + async def need_migrate(self) -> bool: + """判断当前环境是否需要运行此迁移 + """ + return 'anthropic-messages' not in self.ap.provider_cfg.data['requester'] \ + or 'anthropic' not in self.ap.provider_cfg.data['keys'] + + async def run(self): + """执行迁移 + """ + if 'anthropic-messages' not in self.ap.provider_cfg.data['requester']: + self.ap.provider_cfg.data['requester']['anthropic-messages'] = { + 'base-url': 'https://api.anthropic.com/v1', + 'args': { + 'max_tokens': 1024 + }, + 'timeout': 120, + } + + if 'anthropic' not in self.ap.provider_cfg.data['keys']: + self.ap.provider_cfg.data['keys']['anthropic'] = [] + + await self.ap.provider_cfg.dump_config() diff --git a/pkg/core/stages/migrate.py b/pkg/core/stages/migrate.py index edf3cba6..b7685c38 100644 --- a/pkg/core/stages/migrate.py +++ b/pkg/core/stages/migrate.py @@ -4,7 +4,7 @@ from .. import stage, app from ...config import migration -from ...config.migrations import m1_sensitive_word_migration, m2_openai_config_migration +from ...config.migrations import m1_sensitive_word_migration, m2_openai_config_migration, m3_anthropic_requester_cfg_completion @stage.stage_class("MigrationStage")