Private
Public Access
0
0

refactor(ai_client): _send_qwen_result() returns Result[str]

This commit is contained in:
2026-06-12 18:45:23 -04:00
parent e384afce9c
commit 64d6ba2db5
+28 -24
View File
@@ -2420,36 +2420,40 @@ def _list_qwen_models() -> list[str]:
from src.vendor_capabilities import list_models_for_vendor from src.vendor_capabilities import list_models_for_vendor
return list_models_for_vendor("qwen") 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, file_items: list[dict[str, Any]] | None = None,
discussion_history: str = "", discussion_history: str = "",
stream: bool = False, stream: bool = False,
pre_tool_callback: Optional[Callable[[str, str, Optional[Callable[[str], str]]], Optional[str]]] = None, pre_tool_callback: Optional[Callable[[str, str, Optional[Callable[[str], str]]], Optional[str]]] = None,
qa_callback: Optional[Callable[[str], str]] = None, qa_callback: Optional[Callable[[str], str]] = None,
stream_callback: Optional[Callable[[str], None]] = None, stream_callback: Optional[Callable[[str], None]] = None,
patch_callback: Optional[Callable[[str, str], Optional[str]]] = None) -> str: patch_callback: Optional[Callable[[str, str], Optional[str]]] = None) -> Result[str]:
_ensure_qwen_client() from src.qwen_adapter import classify_dashscope_error
with _qwen_history_lock: try:
user_content = user_message _ensure_qwen_client()
if file_items: with _qwen_history_lock:
for fi in file_items: user_content = user_message
if fi.get("is_image") and fi.get("base64_data"): if file_items:
user_content = f"[IMAGE: {fi.get('path', 'attachment')}]\n{user_content}" for fi in file_items:
if discussion_history and not _qwen_history: if fi.get("is_image") and fi.get("base64_data"):
_qwen_history.append({"role": "user", "content": f"[DISCUSSION HISTORY]\n\n{discussion_history}\n\n---\n\n{user_message}"}) user_content = f"[IMAGE: {fi.get('path', 'attachment')}]\n{user_content}"
else: if discussion_history and not _qwen_history:
_qwen_history.append({"role": "user", "content": user_content}) _qwen_history.append({"role": "user", "content": f"[DISCUSSION HISTORY]\n\n{discussion_history}\n\n---\n\n{user_message}"})
messages = [{"role": "system", "content": f"{_get_combined_system_prompt()}\n\n<context>\n{md_content}\n</context>"}] else:
messages.extend(_qwen_history) _qwen_history.append({"role": "user", "content": user_content})
resp = _dashscope_call( messages = [{"role": "system", "content": f"{_get_combined_system_prompt()}\n\n<context>\n{md_content}\n</context>"}]
model=_model, messages.extend(_qwen_history)
messages=messages, resp = _dashscope_call(
tools=None, model=_model,
max_tokens=_max_tokens, messages=messages,
temperature=_temperature, tools=None,
top_p=_top_p, max_tokens=_max_tokens,
) temperature=_temperature,
return resp.get("text", "") 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 #endregion: Qwen Provider