refactor(ai_client): _send_qwen_result() returns Result[str]
This commit is contained in:
+28
-24
@@ -2420,36 +2420,40 @@ def _list_qwen_models() -> list[str]:
|
||||
from src.vendor_capabilities import list_models_for_vendor
|
||||
return list_models_for_vendor("qwen")
|
||||
|
||||
def _send_qwen(md_content: str, user_message: str, base_dir: str,
|
||||
def _send_qwen_result(md_content: str, user_message: str, base_dir: str,
|
||||
file_items: list[dict[str, Any]] | None = None,
|
||||
discussion_history: str = "",
|
||||
stream: bool = False,
|
||||
pre_tool_callback: Optional[Callable[[str, str, Optional[Callable[[str], str]]], Optional[str]]] = None,
|
||||
qa_callback: Optional[Callable[[str], str]] = None,
|
||||
stream_callback: Optional[Callable[[str], None]] = None,
|
||||
patch_callback: Optional[Callable[[str, str], Optional[str]]] = None) -> str:
|
||||
_ensure_qwen_client()
|
||||
with _qwen_history_lock:
|
||||
user_content = user_message
|
||||
if file_items:
|
||||
for fi in file_items:
|
||||
if fi.get("is_image") and fi.get("base64_data"):
|
||||
user_content = f"[IMAGE: {fi.get('path', 'attachment')}]\n{user_content}"
|
||||
if discussion_history and not _qwen_history:
|
||||
_qwen_history.append({"role": "user", "content": f"[DISCUSSION HISTORY]\n\n{discussion_history}\n\n---\n\n{user_message}"})
|
||||
else:
|
||||
_qwen_history.append({"role": "user", "content": user_content})
|
||||
messages = [{"role": "system", "content": f"{_get_combined_system_prompt()}\n\n<context>\n{md_content}\n</context>"}]
|
||||
messages.extend(_qwen_history)
|
||||
resp = _dashscope_call(
|
||||
model=_model,
|
||||
messages=messages,
|
||||
tools=None,
|
||||
max_tokens=_max_tokens,
|
||||
temperature=_temperature,
|
||||
top_p=_top_p,
|
||||
)
|
||||
return resp.get("text", "")
|
||||
patch_callback: Optional[Callable[[str, str], Optional[str]]] = None) -> Result[str]:
|
||||
from src.qwen_adapter import classify_dashscope_error
|
||||
try:
|
||||
_ensure_qwen_client()
|
||||
with _qwen_history_lock:
|
||||
user_content = user_message
|
||||
if file_items:
|
||||
for fi in file_items:
|
||||
if fi.get("is_image") and fi.get("base64_data"):
|
||||
user_content = f"[IMAGE: {fi.get('path', 'attachment')}]\n{user_content}"
|
||||
if discussion_history and not _qwen_history:
|
||||
_qwen_history.append({"role": "user", "content": f"[DISCUSSION HISTORY]\n\n{discussion_history}\n\n---\n\n{user_message}"})
|
||||
else:
|
||||
_qwen_history.append({"role": "user", "content": user_content})
|
||||
messages = [{"role": "system", "content": f"{_get_combined_system_prompt()}\n\n<context>\n{md_content}\n</context>"}]
|
||||
messages.extend(_qwen_history)
|
||||
resp = _dashscope_call(
|
||||
model=_model,
|
||||
messages=messages,
|
||||
tools=None,
|
||||
max_tokens=_max_tokens,
|
||||
temperature=_temperature,
|
||||
top_p=_top_p,
|
||||
)
|
||||
return Result(data=resp.get("text", ""))
|
||||
except Exception as exc:
|
||||
return Result(data="", errors=[classify_dashscope_error(exc, source="ai_client.qwen")])
|
||||
|
||||
#endregion: Qwen Provider
|
||||
|
||||
|
||||
Reference in New Issue
Block a user