feat(ai_client): migrate _send_grok to provider_state.get_history('grok')
This commit is contained in:
+8
-7
@@ -2568,19 +2568,20 @@ def _send_grok(md_content: str, user_message: str, base_dir: str,
|
||||
client = _ensure_grok_client()
|
||||
tools: list[Metadata] | None = _get_deepseek_tools() or None
|
||||
caps = get_capabilities("grok", _model)
|
||||
with _grok_history_lock:
|
||||
history = provider_state.get_history("grok")
|
||||
with 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 _grok_history:
|
||||
_grok_history.append({"role": "user", "content": f"[DISCUSSION HISTORY]\n\n{discussion_history}\n\n---\n\n{user_message}"})
|
||||
if discussion_history and not history:
|
||||
history.append({"role": "user", "content": f"[DISCUSSION HISTORY]\n\n{discussion_history}\n\n---\n\n{user_message}"})
|
||||
else:
|
||||
_grok_history.append({"role": "user", "content": user_content})
|
||||
history.append({"role": "user", "content": user_content})
|
||||
def _build_grok_request(_round_idx: int) -> OpenAICompatibleRequest:
|
||||
with _grok_history_lock:
|
||||
history_msgs: list[ChatMessage] = [ChatMessage(role=m["role"], content=m["content"]) for m in _grok_history]
|
||||
with history.lock:
|
||||
history_msgs: list[ChatMessage] = [ChatMessage(role=m["role"], content=m["content"]) for m in history]
|
||||
messages: list[ChatMessage] = [ChatMessage(role="system", content=f"{_get_combined_system_prompt()}\n\n<context>\n{md_content}\n</context>")]
|
||||
messages.extend(history_msgs)
|
||||
extra_body: Metadata = {}
|
||||
@@ -2599,7 +2600,7 @@ def _send_grok(md_content: str, user_message: str, base_dir: str,
|
||||
client, _build_grok_request, capabilities=caps,
|
||||
pre_tool_callback=pre_tool_callback, qa_callback=qa_callback, stream_callback=stream_callback,
|
||||
patch_callback=patch_callback, base_dir=base_dir, vendor_name="grok",
|
||||
history_lock=_grok_history_lock, history=_grok_history,
|
||||
history_lock=history.lock, history=history,
|
||||
))
|
||||
except Exception as exc:
|
||||
return Result(data="", errors=[_classify_openai_compatible_error(exc, source="ai_client.grok")])
|
||||
|
||||
Reference in New Issue
Block a user