Skip to content

Commit

Permalink
chore (backend): ensure date strings are converted to datetime before…
Browse files Browse the repository at this point in the history
… seconds computation
  • Loading branch information
aybruhm committed Dec 6, 2024
1 parent adc50f3 commit f6a50dc
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions agenta-backend/agenta_backend/services/llm_apps_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,20 @@ def extract_result_from_response(response: dict):
if "tree" in response:
trace_tree = response.get("tree", {}).get("nodes", [])[0]

duration_ms = get_nested_value(trace_tree, ["metrics", "acc", "duration", "total"])
duration_ms = get_nested_value(
trace_tree, ["metrics", "acc", "duration", "total"]
)
if duration_ms:
duration_seconds = duration_ms / 1000
else:
start_time = get_nested_value(trace_tree, ["time", "start"])
end_time = get_nested_value(trace_tree, ["time", "end"])

if start_time and end_time:
duration_seconds = (datetime(end_time) - datetime(start_time)).total_seconds()
duration_seconds = (
datetime.fromisoformat(end_time)
- datetime.fromisoformat(start_time)
).total_seconds()
else:
duration_seconds = None

Expand Down

0 comments on commit f6a50dc

Please sign in to comment.