Skip to content

Commit 53b48ae

Browse files
committed
feat(log): include model in response logs
1 parent 1265568 commit 53b48ae

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

llmcore.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -800,7 +800,7 @@ def chat(self, messages, tools=None):
800800
raw_text = ''
801801
for chunk in gen:
802802
raw_text += chunk; yield chunk
803-
_write_llm_log('Response', raw_text, self.log_path)
803+
_write_llm_log('Response', raw_text, self.log_path, model=self.backend.model)
804804
return self._parse_mixed_response(raw_text)
805805

806806
def _prepare_tool_instruction(self, tools):
@@ -917,13 +917,14 @@ def _ensure_text_block(blocks):
917917
blocks.insert(1, {"type": "text", "text": txt})
918918
return txt
919919

920-
def _write_llm_log(label, content, log_path=None):
920+
def _write_llm_log(label, content, log_path=None, model=''):
921921
if not log_path:
922922
log_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), f'temp/model_responses/model_responses_{os.getpid()}.txt')
923923
os.makedirs(os.path.dirname(os.path.abspath(log_path)), exist_ok=True)
924924
ts = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
925+
if model: model = f' model={model}'
925926
with open(log_path, 'a', encoding='utf-8', errors='replace') as f:
926-
f.write(f"=== {label} === {ts}\n{content}\n\n")
927+
f.write(f"=== {label} === {ts}{model}\n{content}\n\n")
927928

928929
def tryparse(json_str):
929930
try: return json.loads(json_str)
@@ -1053,7 +1054,7 @@ def chat(self, messages, tools=None):
10531054
while True:
10541055
chunk = next(gen); yield chunk
10551056
except StopIteration as e: resp = e.value
1056-
if resp: _write_llm_log('Response', resp.raw, self.log_path)
1057+
if resp: _write_llm_log('Response', resp.raw, self.log_path, model=self.backend.model)
10571058
if resp and hasattr(resp, 'tool_calls') and resp.tool_calls: self._pending_tool_ids = [tc.id for tc in resp.tool_calls]
10581059
return resp
10591060

0 commit comments

Comments
 (0)