From bdbaab9b3cc694b4a8378112924e5f2c92e73df5 Mon Sep 17 00:00:00 2001 From: Jiaqing Liang Date: Thu, 18 Jun 2026 14:26:04 +0800 Subject: [PATCH] feat(log): include model in response logs --- llmcore.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/llmcore.py b/llmcore.py index a584b5f2..38fe2237 100644 --- a/llmcore.py +++ b/llmcore.py @@ -800,7 +800,7 @@ class ToolClient: raw_text = '' for chunk in gen: raw_text += chunk; yield chunk - _write_llm_log('Response', raw_text, self.log_path) + _write_llm_log('Response', raw_text, self.log_path, model=self.backend.model) return self._parse_mixed_response(raw_text) def _prepare_tool_instruction(self, tools): @@ -917,13 +917,14 @@ def _ensure_text_block(blocks): blocks.insert(1, {"type": "text", "text": txt}) return txt -def _write_llm_log(label, content, log_path=None): +def _write_llm_log(label, content, log_path=None, model=''): if not log_path: log_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), f'temp/model_responses/model_responses_{os.getpid()}.txt') os.makedirs(os.path.dirname(os.path.abspath(log_path)), exist_ok=True) ts = datetime.now().strftime('%Y-%m-%d %H:%M:%S') + if model: model = f' model={model}' with open(log_path, 'a', encoding='utf-8', errors='replace') as f: - f.write(f"=== {label} === {ts}\n{content}\n\n") + f.write(f"=== {label} === {ts}{model}\n{content}\n\n") def tryparse(json_str): try: return json.loads(json_str) @@ -1053,7 +1054,7 @@ class NativeToolClient: while True: chunk = next(gen); yield chunk except StopIteration as e: resp = e.value - if resp: _write_llm_log('Response', resp.raw, self.log_path) + if resp: _write_llm_log('Response', resp.raw, self.log_path, model=self.backend.model) if resp and hasattr(resp, 'tool_calls') and resp.tool_calls: self._pending_tool_ids = [tc.id for tc in resp.tool_calls] return resp