Spaces:
Running
Running
github-actions[bot]
commited on
Commit
Β·
980d57f
1
Parent(s):
55a3068
Sync with https://github.com/mozilla-ai/surf-spot-finder
Browse files
utils.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
import json
|
2 |
from typing import Any
|
3 |
import streamlit as st
|
|
|
4 |
from surf_spot_finder.tools import (
|
5 |
driving_hours_to_meters,
|
6 |
get_area_lat_lon,
|
@@ -10,7 +11,7 @@ from surf_spot_finder.tools import (
|
|
10 |
)
|
11 |
from surf_spot_finder.config import Config
|
12 |
from any_agent import AgentConfig, AnyAgent, TracingConfig
|
13 |
-
from any_agent.tracing.trace import AgentTrace
|
14 |
from any_agent.tracing.otel_types import StatusCode
|
15 |
from any_agent.evaluation import evaluate, TraceEvaluationResult
|
16 |
|
@@ -66,11 +67,24 @@ async def run_agent(user_inputs: dict[str, Any]):
|
|
66 |
st.markdown("#### π Query")
|
67 |
st.code(query, language="text")
|
68 |
|
|
|
69 |
with st.spinner("π€ Analyzing surf spots..."):
|
70 |
agent_trace: AgentTrace = await agent.run_async(query)
|
71 |
agent.exit()
|
72 |
|
|
|
|
|
|
|
|
|
|
|
73 |
st.markdown("### π Results")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
st.markdown("#### Final Output")
|
75 |
st.info(agent_trace.final_output)
|
76 |
|
|
|
1 |
import json
|
2 |
from typing import Any
|
3 |
import streamlit as st
|
4 |
+
import time
|
5 |
from surf_spot_finder.tools import (
|
6 |
driving_hours_to_meters,
|
7 |
get_area_lat_lon,
|
|
|
11 |
)
|
12 |
from surf_spot_finder.config import Config
|
13 |
from any_agent import AgentConfig, AnyAgent, TracingConfig
|
14 |
+
from any_agent.tracing.trace import AgentTrace, TotalTokenUseAndCost
|
15 |
from any_agent.tracing.otel_types import StatusCode
|
16 |
from any_agent.evaluation import evaluate, TraceEvaluationResult
|
17 |
|
|
|
67 |
st.markdown("#### π Query")
|
68 |
st.code(query, language="text")
|
69 |
|
70 |
+
start_time = time.time()
|
71 |
with st.spinner("π€ Analyzing surf spots..."):
|
72 |
agent_trace: AgentTrace = await agent.run_async(query)
|
73 |
agent.exit()
|
74 |
|
75 |
+
end_time = time.time()
|
76 |
+
execution_time = end_time - start_time
|
77 |
+
|
78 |
+
cost: TotalTokenUseAndCost = agent_trace.get_total_cost()
|
79 |
+
|
80 |
st.markdown("### π Results")
|
81 |
+
time_col, cost_col, tokens_col = st.columns(3)
|
82 |
+
with time_col:
|
83 |
+
st.info(f"β±οΈ Execution Time: {execution_time:.2f} seconds")
|
84 |
+
with cost_col:
|
85 |
+
st.info(f"π° Estimated Cost: ${cost.total_cost:.6f}")
|
86 |
+
with tokens_col:
|
87 |
+
st.info(f"π¦ Total Tokens: {cost.total_tokens:,}")
|
88 |
st.markdown("#### Final Output")
|
89 |
st.info(agent_trace.final_output)
|
90 |
|