落地私聊图片询价:识图当口播复用三线文字流程,图上航线三字码保持原样,避免被改写成中文地名。
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -19,6 +19,42 @@ from agent.llm.modes import LlmMode
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def message_plain_text(msg: dict[str, Any]) -> str:
|
||||
"""
|
||||
把 assistant message 收成纯文本。
|
||||
|
||||
千问视觉的 content 经常是 [{text: ...}] 数组,不是字符串;
|
||||
思考模式打开时正文可能只在 reasoning_content。两者都漏会让识图变「没看清」。
|
||||
"""
|
||||
if not isinstance(msg, dict):
|
||||
return ""
|
||||
text = _content_to_text(msg.get("content"))
|
||||
if text:
|
||||
return text
|
||||
reason = msg.get("reasoning_content")
|
||||
if isinstance(reason, str) and reason.strip():
|
||||
return reason.strip()
|
||||
return ""
|
||||
|
||||
|
||||
def _content_to_text(content: Any) -> str:
|
||||
"""字符串或千问多模态数组 → 纯文本。"""
|
||||
if isinstance(content, str):
|
||||
return content.strip()
|
||||
if isinstance(content, list):
|
||||
parts: list[str] = []
|
||||
for item in content:
|
||||
if isinstance(item, str) and item.strip():
|
||||
parts.append(item.strip())
|
||||
elif isinstance(item, dict):
|
||||
piece = item.get("text") if "text" in item else item.get("content")
|
||||
got = _content_to_text(piece)
|
||||
if got:
|
||||
parts.append(got)
|
||||
return "\n".join(parts).strip()
|
||||
return ""
|
||||
|
||||
|
||||
@dataclass
|
||||
class LlmHttpResult:
|
||||
ok: bool
|
||||
@@ -72,7 +108,7 @@ class LlmHttpClient:
|
||||
mode_val = mode.value if isinstance(mode, LlmMode) else str(mode)
|
||||
if provider == "qwen":
|
||||
if mode_val == LlmMode.VISION.value:
|
||||
return self.settings.qwen_vl_model or "qwen-vl-plus"
|
||||
return self.settings.qwen_vl_model or "qwen3-vl-plus"
|
||||
return self.settings.qwen_text_model or "qwen-plus"
|
||||
return self.settings.deepseek_model or "deepseek-chat"
|
||||
|
||||
@@ -115,6 +151,9 @@ class LlmHttpClient:
|
||||
"messages": messages,
|
||||
"temperature": temperature,
|
||||
}
|
||||
if provider == "qwen":
|
||||
# 识图只要可见原文。思考开着时 content 常为空,销售侧就会「认不到」。
|
||||
body["enable_thinking"] = False
|
||||
if tools:
|
||||
body["tools"] = tools
|
||||
if tool_choice is not None:
|
||||
@@ -147,7 +186,7 @@ class LlmHttpClient:
|
||||
tool_calls: list[dict[str, Any]] = []
|
||||
if choices:
|
||||
msg = (choices[0].get("message") or {})
|
||||
content = str(msg.get("content") or "")
|
||||
content = message_plain_text(msg if isinstance(msg, dict) else {})
|
||||
raw_calls = msg.get("tool_calls") or []
|
||||
if isinstance(raw_calls, list):
|
||||
tool_calls = [c for c in raw_calls if isinstance(c, dict)]
|
||||
|
||||
Reference in New Issue
Block a user