Private
Public Access
0
0

feat(ai_client): migrate _send_grok to provider_state.get_history('grok')

This commit is contained in:
2026-06-25 12:20:02 -04:00
parent 35c708defe
commit 94a136ca32
+8 -7
View File
@@ -2568,19 +2568,20 @@ def _send_grok(md_content: str, user_message: str, base_dir: str,
client = _ensure_grok_client() client = _ensure_grok_client()
tools: list[Metadata] | None = _get_deepseek_tools() or None tools: list[Metadata] | None = _get_deepseek_tools() or None
caps = get_capabilities("grok", _model) caps = get_capabilities("grok", _model)
with _grok_history_lock: history = provider_state.get_history("grok")
with history.lock:
user_content = user_message user_content = user_message
if file_items: if file_items:
for fi in file_items: for fi in file_items:
if fi.get("is_image") and fi.get("base64_data"): if fi.get("is_image") and fi.get("base64_data"):
user_content = f"[IMAGE: {fi.get('path', 'attachment')}]\n{user_content}" user_content = f"[IMAGE: {fi.get('path', 'attachment')}]\n{user_content}"
if discussion_history and not _grok_history: if discussion_history and not history:
_grok_history.append({"role": "user", "content": f"[DISCUSSION HISTORY]\n\n{discussion_history}\n\n---\n\n{user_message}"}) history.append({"role": "user", "content": f"[DISCUSSION HISTORY]\n\n{discussion_history}\n\n---\n\n{user_message}"})
else: else:
_grok_history.append({"role": "user", "content": user_content}) history.append({"role": "user", "content": user_content})
def _build_grok_request(_round_idx: int) -> OpenAICompatibleRequest: def _build_grok_request(_round_idx: int) -> OpenAICompatibleRequest:
with _grok_history_lock: with history.lock:
history_msgs: list[ChatMessage] = [ChatMessage(role=m["role"], content=m["content"]) for m in _grok_history] 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: list[ChatMessage] = [ChatMessage(role="system", content=f"{_get_combined_system_prompt()}\n\n<context>\n{md_content}\n</context>")]
messages.extend(history_msgs) messages.extend(history_msgs)
extra_body: Metadata = {} 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, client, _build_grok_request, capabilities=caps,
pre_tool_callback=pre_tool_callback, qa_callback=qa_callback, stream_callback=stream_callback, 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", 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: except Exception as exc:
return Result(data="", errors=[_classify_openai_compatible_error(exc, source="ai_client.grok")]) return Result(data="", errors=[_classify_openai_compatible_error(exc, source="ai_client.grok")])