feat(log): include model in response logs

This commit is contained in:
Jiaqing Liang committed 2026-06-18 14:26:04 +08:00
1 parent 12655687aa
commit 53b48aea07
1 file changed
+5 -4
+5 -4
View File
@@ -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