Commit c58be6a8 authored by Kantz's avatar Kantz
Browse files

nur noch ein tool_logging datei

parent 52993fbc
......@@ -71,5 +71,9 @@ def run_chat(messages: list[dict], draft: str | None = None) -> dict:
reply = "Dazu steht nichts im Material"
context_store.save_sheet(sheet)
tool_logging.write_tool_log(tool_log)
tool_logging.write_tool_log(
tool_log,
created_at=sheet.get("created_at"),
chat_id=sheet.get("chat_id"),
)
return {"reply": reply, "sources": sheet.get("sources", []), "tool_log": tool_log}
......@@ -3,10 +3,30 @@ import os
from datetime import datetime
def write_tool_log(entries: list[dict]) -> str:
def _format_log_timestamp(created_at: str | None) -> str:
if not created_at:
return datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%SZ")
try:
parsed = datetime.strptime(created_at, "%Y-%m-%dT%H:%M:%SZ")
return parsed.strftime("%Y-%m-%dT%H:%M:%SZ")
except ValueError:
return created_at
def _format_filename_timestamp(timestamp: str) -> str:
try:
parsed = datetime.strptime(timestamp, "%Y-%m-%dT%H:%M:%SZ")
return parsed.strftime("%Y%m%d_%H%M%S")
except ValueError:
return timestamp.replace("-", "").replace(":", "").replace("T", "_").replace("Z", "")
def write_tool_log(entries: list[dict], created_at: str | None = None, chat_id: str | None = None) -> str:
os.makedirs("logs", exist_ok=True)
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
path = os.path.join("logs", f"tool_calls_{timestamp}.json")
timestamp = _format_log_timestamp(created_at)
filename_ts = _format_filename_timestamp(timestamp)
suffix = chat_id or "latest"
path = os.path.join("logs", f"tool_calls_{suffix}_{filename_ts}.json")
payload = {
"timestamp": timestamp,
"entries": entries,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment