-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
feat: implement Aliyun Bailian Chat provider and coding plan support #5718
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| from ..register import register_provider_adapter | ||
| from .openai_source import ProviderOpenAIOfficial | ||
|
|
||
|
|
||
| @register_provider_adapter( | ||
| "bailian_chat_completion", | ||
| "阿里云百炼 Chat Completion 提供商适配器", | ||
| provider_display_name="百炼", | ||
| ) | ||
| class ProviderBailianChat(ProviderOpenAIOfficial): | ||
| def __init__( | ||
| self, | ||
| provider_config: dict, | ||
| provider_settings: dict, | ||
| ) -> None: | ||
| # 根据 Coding Plan 模式自动切换 API Base URL | ||
| is_coding_plan = provider_config.get("bl_coding_plan", False) | ||
| is_thinking = provider_config.get("bl_thinking", False) | ||
|
|
||
| if is_coding_plan: | ||
| provider_config["api_base"] = "https://coding.dashscope.aliyuncs.com/v1" | ||
| else: | ||
| provider_config["api_base"] = ( | ||
| "https://dashscope.aliyuncs.com/compatible-mode/v1" | ||
| ) | ||
|
|
||
| if is_thinking and not provider_config.get("model"): | ||
| if is_coding_plan: | ||
| provider_config["model"] = "qwen3.5-plus" | ||
| else: | ||
| provider_config["model"] = "qwen-plus" | ||
|
|
||
| super().__init__(provider_config, provider_settings) | ||
| self.is_thinking = is_thinking | ||
|
|
||
| def _finally_convert_payload(self, payloads: dict) -> None: | ||
| """添加百炼特定参数""" | ||
| super()._finally_convert_payload(payloads) | ||
|
|
||
| if self.is_thinking: | ||
| payloads["enable_thinking"] = True | ||
|
|
||
| def _extract_reasoning_content(self, completion) -> str: | ||
| """提取推理内容""" | ||
| return super()._extract_reasoning_content(completion) | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -443,6 +443,14 @@ async def update_provider_source(self): | |||||||||||||||||||||||||||||||||
| if not isinstance(new_source_config, dict): | ||||||||||||||||||||||||||||||||||
| return Response().error("缺少或错误的配置数据").__dict__ | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| # 百炼 Chat Completion: 根据 bl_coding_plan 强制设置正确的 api_base | ||||||||||||||||||||||||||||||||||
| if new_source_config.get("type") == "bailian_chat_completion": | ||||||||||||||||||||||||||||||||||
| is_coding_plan = new_source_config.get("bl_coding_plan", False) | ||||||||||||||||||||||||||||||||||
| if is_coding_plan: | ||||||||||||||||||||||||||||||||||
| new_source_config["api_base"] = "https://coding.dashscope.aliyuncs.com/v1" | ||||||||||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||||||||||
| new_source_config["api_base"] = "https://dashscope.aliyuncs.com/compatible-mode/v1" | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+447
to
+452
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: 避免在多个地方硬编码百炼的基础 URL,以降低配置漂移风险。 这些 dashscope 的基础 URL 目前在这里以及 建议的实现方式: # 百炼 Chat Completion: 根据 bl_coding_plan 强制设置正确的 api_base
if new_source_config.get("type") == "bailian_chat_completion":
is_coding_plan = new_source_config.get("bl_coding_plan", False)
if is_coding_plan:
new_source_config["api_base"] = BAILIAN_CODING_API_BASE
else:
new_source_config["api_base"] = BAILIAN_COMPATIBLE_MODE_API_BASE为了完整落实这一建议并避免 URL 漂移:
如果你们代码库中实际的 provider 模块路径或命名不同,请相应调整上述 import 中的模块名。 Original comment in Englishsuggestion: Avoid hard-coding the 百炼 base URLs in multiple places to reduce drift risk. These dashscope base URLs are now defined both here and in Suggested implementation: # 百炼 Chat Completion: 根据 bl_coding_plan 强制设置正确的 api_base
if new_source_config.get("type") == "bailian_chat_completion":
is_coding_plan = new_source_config.get("bl_coding_plan", False)
if is_coding_plan:
new_source_config["api_base"] = BAILIAN_CODING_API_BASE
else:
new_source_config["api_base"] = BAILIAN_COMPATIBLE_MODE_API_BASETo fully implement the suggestion and avoid URL drift:
If the actual provider module path or naming differs in your codebase, adjust the module name in the import accordingly.
Comment on lines
+447
to
+452
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 您好,这部分用于确定阿里云百炼 为了提高代码的可维护性,建议将这些 URL 定义为常量,并在两处复用。一个好的实践是将常量定义在 建议修改:
Suggested change
|
||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| # 确保配置中有 id 字段 | ||||||||||||||||||||||||||||||||||
| if not new_source_config.get("id"): | ||||||||||||||||||||||||||||||||||
| new_source_config["id"] = original_id | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_extract_reasoning_content方法是对父类方法的空覆写,它只是简单地调用了super()。这个方法是多余的,可以安全地移除,以使代码更简洁。移除后,程序将自动调用父类的实现,行为不会改变。