-
Notifications
You must be signed in to change notification settings - Fork 565
fix(ai): introduce message truncation for openai #4946
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 7 commits
507bf17
7d80e04
bb5973c
52b7f6e
b4dcfc7
6d4c89b
84bfabb
8e45aa3
4fb6289
405a096
12dcf5d
cf9d809
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -598,6 +598,23 @@ def _prepare_event( | |
if event_scrubber: | ||
event_scrubber.scrub_event(event) | ||
|
||
if scope is not None and scope._gen_ai_messages_truncated: | ||
spans = event.get("spans", []) # type: List[Dict[str, Any]] | AnnotatedValue[List[Dict[str, Any]]] | ||
for span in spans: | ||
span_id = span.get("span_id", None) | ||
span_data = span.get("data", {}) | ||
if ( | ||
span_id | ||
and span_id in scope._gen_ai_messages_truncated | ||
and SPANDATA.GEN_AI_REQUEST_MESSAGES in span_data | ||
): | ||
span_data[SPANDATA.GEN_AI_REQUEST_MESSAGES] = AnnotatedValue( | ||
span_data[SPANDATA.GEN_AI_REQUEST_MESSAGES], | ||
{ | ||
"len": scope._gen_ai_messages_truncated[span_id] | ||
+ len(span_data[SPANDATA.GEN_AI_REQUEST_MESSAGES]) | ||
}, | ||
) | ||
|
||
if previous_total_spans is not None: | ||
event["spans"] = AnnotatedValue( | ||
event.get("spans", []), {"len": previous_total_spans} | ||
|
@@ -606,6 +623,7 @@ def _prepare_event( | |
event["breadcrumbs"] = AnnotatedValue( | ||
event.get("breadcrumbs", []), {"len": previous_total_breadcrumbs} | ||
) | ||
|
||
# Postprocess the event here so that annotated types do | ||
# generally not surface in before_send | ||
if event is not None: | ||
|
Uh oh!
There was an error while loading. Please reload this page.