Skip to content

Commit c31d4a4

Browse files
committed
Better output
1 parent 20c5343 commit c31d4a4

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

sentry_sdk/consts.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,12 @@ class SPANDATA:
372372
Example: "chat"
373373
"""
374374

375+
GEN_AI_RESPONSE_TEXT = "gen_ai.response.text"
376+
"""
377+
The model's response text messages.
378+
Example: ["The weather in Paris is rainy and overcast, with temperatures around 57°F", "The weather in London is sunny and warm, with temperatures around 65°F"]
379+
"""
380+
375381
GEN_AI_RESPONSE_TOOL_CALLS = "gen_ai.response.tool_calls"
376382
"""
377383
The tool calls in the model's response.

sentry_sdk/integrations/openai_agents/utils.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -202,14 +202,14 @@ def _set_output_data(span, result):
202202
output_messages["tool"].append(output.dict())
203203
elif output.type == "message":
204204
for output_message in output.content:
205-
output_messages["response"].append(output_message.to_json())
205+
try:
206+
output_messages["response"].append(output_message.text)
207+
except AttributeError:
208+
# Unknown output message type, just return the json
209+
output_messages["response"].append(output_message.to_json())
206210

207211
if len(output_messages["tool"]) > 0:
208212
span.set_data(SPANDATA.GEN_AI_RESPONSE_TOOL_CALLS, output_messages["tool"])
209213

210214
if len(output_messages["response"]) > 0:
211-
span.set_data(SPANDATA.GEN_AI_CHOICE, output_messages["response"])
212-
213-
# Deprecated name just for first iteration.
214-
# TODO-anton: define how to set tool response messages and document in sentry-conventions.
215-
span.set_data("gen_ai.response.text", output_messages["response"])
215+
span.set_data(SPANDATA.GEN_AI_RESPONSE_TEXT, output_messages["response"])

0 commit comments

Comments
 (0)