Skip to content

Commit eb78eb3

Browse files
committed
trace save
1 parent 74b2c2e commit eb78eb3

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

src/demo/sequence_test.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
@tracer.observe(span_type="tool")
1919
def search_tavily(query):
2020
"""Fetch travel data using Tavily API."""
21-
return "results"
21+
return "The weather in Tokyo is sunny with a high of 75°F."
2222

2323
# @judgment.observe(span_type="tool")
2424
def get_attractions(destination):
@@ -46,6 +46,15 @@ def get_weather(destination, start_date, end_date):
4646
"""Search for weather information."""
4747
prompt = f"Weather forecast for {destination} from {start_date} to {end_date}"
4848
weather_search = search_tavily(prompt)
49+
example = Example(
50+
input="What is the weather in Tokyo?",
51+
actual_output=weather_search
52+
)
53+
tracer.async_evaluate(
54+
scorers=[AnswerRelevancyScorer(threshold=0.5)],
55+
example=example,
56+
model="gpt-4o-mini",
57+
)
4958
return weather_search
5059

5160
def research_destination(destination, start_date, end_date):
@@ -137,13 +146,13 @@ def generate_itinerary(destination, start_date, end_date):
137146
{"tool_name": "search_tavily", "parameters": {"query": "Best tourist attractions in Tokyo"}},
138147
{"tool_name": "search_tavily", "parameters": {"query": "Best hotels in Tokyo"}},
139148
{"tool_name": "search_tavily", "parameters": {"query": "Flights to Tokyo from major cities"}},
140-
{"tool_name": "search_tavily", "parameters": {"query": "Weather forecast for Tokyo from 2025-06-01 to 2025-06-02"}}
149+
{"tool_name": "search_tavily", "parameters": {"query": "Weather forecast for Tokyo from 2025-06-01 to 2025-06-03"}}
141150
]
142151
)
143152

144153
judgment.assert_test(
145154
project_name="travel_agent_demo",
146-
examples=[example],
155+
examples=[example, example2],
147156
scorers=[ToolOrderScorer(threshold=0.5)],
148157
model="gpt-4.1-mini",
149158
function=generate_itinerary,

src/judgeval/common/tracer.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ def fetch_trace(self, trace_id: str):
146146

147147
return response.json()
148148

149-
def save_trace(self, trace_data: dict):
149+
def save_trace(self, trace_data: dict, offline_mode: bool = False):
150150
"""
151151
Saves a trace to the Judgment Supabase and optionally to S3 if configured.
152152
@@ -183,7 +183,7 @@ def save_trace(self, trace_data: dict):
183183
except Exception as e:
184184
warnings.warn(f"Failed to save trace to S3: {str(e)}")
185185

186-
if "ui_results_url" in response.json():
186+
if not offline_mode and "ui_results_url" in response.json():
187187
pretty_str = f"\n🔍 You can view your trace data here: [rgb(106,0,255)][link={response.json()['ui_results_url']}]View Trace[/link]\n"
188188
rprint(pretty_str)
189189

@@ -665,8 +665,7 @@ def save(self, overwrite: bool = False) -> Tuple[str, dict]:
665665
"parent_name": self.parent_name
666666
}
667667
# --- Log trace data before saving ---
668-
if not self.tracer.offline_mode:
669-
self.trace_manager_client.save_trace(trace_data)
668+
self.trace_manager_client.save_trace(trace_data, offline_mode=self.tracer.offline_mode)
670669

671670
# upload annotations
672671
# TODO: batch to the log endpoint

src/judgeval/data/trace.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ class Trace(BaseModel):
126126
duration: float
127127
entries: List[TraceSpan]
128128
overwrite: bool = False
129+
offline_mode: bool = False
129130
rules: Optional[Dict[str, Any]] = None
130131
has_notification: Optional[bool] = False
131132

0 commit comments

Comments
 (0)