mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2026-10-22 04:30:05 +08:00
✨ feat(llm): 优化 DeepSeek 适配器 (#2160)
检查bot是否运行正常 / bot check (push) Canceled after 0s
CodeQL Code Security Analysis / Analyze (python) (push) Canceled after 0s
Ruff Lint / Ruff Lint (push) Canceled after 0s
Sequential Lint and Type Check / ruff-call (push) Canceled after 0s
Release Drafter / Update Release Draft (push) Canceled after 0s
Force Sync to Aliyun / sync (push) Canceled after 0s
Update Version / update-version (push) Canceled after 0s
Sequential Lint and Type Check / pyright-call (push) Canceled after 0s
检查bot是否运行正常 / bot check (push) Canceled after 0s
CodeQL Code Security Analysis / Analyze (python) (push) Canceled after 0s
Ruff Lint / Ruff Lint (push) Canceled after 0s
Sequential Lint and Type Check / ruff-call (push) Canceled after 0s
Release Drafter / Update Release Draft (push) Canceled after 0s
Force Sync to Aliyun / sync (push) Canceled after 0s
Update Version / update-version (push) Canceled after 0s
Sequential Lint and Type Check / pyright-call (push) Canceled after 0s
* ✨ feat(llm): 新增 Grok 适配器及 API 密钥重置指令 - 新增 Grok 适配器并支持原生推特检索工具 `x_search` - 优化 DeepSeek 适配器以迁移至 Responses 协议,增强多模态支持 - 在 LLM 管理插件中新增 `llm reset` 子命令以重置 Key 状态 - 增强 MCP 连接异常处理及流关闭容错能力 * 🚨 auto fix by pre-commit hooks --------- Co-authored-by: webjoin111 <455457521@qq.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
co-authored by
webjoin111
pre-commit-ci[bot]
parent
39ed1ade14
commit
33d6ea1335
@@ -521,6 +521,9 @@ class ResponsesConfigMapper(OpenAIConfigMapper):
|
||||
class ResponsesMessageConverter(MessageConverter):
|
||||
"""针对 OpenAI Responses API 的消息转换器"""
|
||||
|
||||
def __init__(self, api_type: str = "openai_responses"):
|
||||
self.api_type = api_type
|
||||
|
||||
async def convert_messages_async(
|
||||
self, messages: list[LLMMessage]
|
||||
) -> list[dict[str, Any]]:
|
||||
@@ -543,11 +546,14 @@ class ResponsesMessageConverter(MessageConverter):
|
||||
continue
|
||||
|
||||
content_list: list[dict[str, Any]] = []
|
||||
thought_text = ""
|
||||
for part in msg.content:
|
||||
if part is None:
|
||||
continue
|
||||
|
||||
if isinstance(part, TextPart):
|
||||
if isinstance(part, ThoughtPart):
|
||||
thought_text += part.thought_text
|
||||
elif isinstance(part, TextPart):
|
||||
c_type = "output_text" if role == "assistant" else "input_text"
|
||||
content_list.append({"type": c_type, "text": part.text})
|
||||
elif isinstance(part, ImagePart):
|
||||
@@ -573,6 +579,26 @@ class ResponsesMessageConverter(MessageConverter):
|
||||
{"type": "input_image", "image_url": image_src}
|
||||
)
|
||||
|
||||
if role == "assistant" and thought_text:
|
||||
if self.api_type == "deepseek":
|
||||
input_items.append(
|
||||
{
|
||||
"type": "reasoning",
|
||||
"content": [
|
||||
{"type": "reasoning_text", "text": thought_text}
|
||||
],
|
||||
"summary": [],
|
||||
}
|
||||
)
|
||||
else:
|
||||
input_items.append(
|
||||
{
|
||||
"type": "reasoning",
|
||||
"content": [],
|
||||
"summary": [{"type": "summary_text", "text": thought_text}],
|
||||
}
|
||||
)
|
||||
|
||||
if content_list:
|
||||
input_items.append({"role": role, "content": content_list})
|
||||
|
||||
@@ -661,6 +687,10 @@ class ResponsesResponseParser(OpenAIResponseParser):
|
||||
)
|
||||
)
|
||||
elif item.get("type") == "reasoning":
|
||||
for r_content in item.get("content", []):
|
||||
if r_content.get("type") == "reasoning_text":
|
||||
thought_content += r_content.get("text", "")
|
||||
|
||||
for summary_item in item.get("summary", []):
|
||||
if summary_item.get("type") == "summary_text":
|
||||
thought_content += summary_item.get("text", "")
|
||||
@@ -868,7 +898,7 @@ class OpenAIResponsesTextHandler(OpenAITextHandler):
|
||||
|
||||
def __init__(self, api_type: str = "openai_responses"):
|
||||
super().__init__(api_type=api_type)
|
||||
self.converter = ResponsesMessageConverter()
|
||||
self.converter = ResponsesMessageConverter(api_type=api_type)
|
||||
self.serializer = ResponsesToolSerializer(api_type=api_type)
|
||||
self.mapper = ResponsesConfigMapper(api_type=api_type)
|
||||
self.parser = ResponsesResponseParser()
|
||||
|
||||
Reference in New Issue
Block a user