Skip to content

Commit db4bc9e

Browse files
darshit-s3rohit-kadhealizenhomkarthikscale3
authored
Release: handling for openai NOT_GIVEN default arg value (#351)
* add sentry integration * update readme * hotfix for checking package installed * Support Autogen (#242) * autogen kickstart * enhance autogen * run autogen * finish autogen * add readme * disable cache * Support genai and also add token reporting and other data points (#345) * support genai and also add token reporting * rename example file * fix --------- Co-authored-by: Karthik Kalyanaraman <[email protected]> * fix: weaviate datetime handling for request and response (#346) * fix: weaviate datetime handling for request and response * bump version * bump version --------- Co-authored-by: Karthik Kalyanaraman <[email protected]> * Minor bugfix to langchain instrumentation (#348) * Bugfix * bump version * fix: handling for openai NOT_GIVEN default arg value (#350) * fix: handling for openai NOT_GIVEN default arg value * style: fix formating --------- Co-authored-by: Rohit Kadhe <[email protected]> Co-authored-by: Rohit Kadhe <[email protected]> Co-authored-by: Ali Waleed <[email protected]> Co-authored-by: Karthik Kalyanaraman <[email protected]> Co-authored-by: Karthik Kalyanaraman <[email protected]>
1 parent e8bb36f commit db4bc9e

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

src/langtrace_python_sdk/instrumentation/openai/patch.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import json
2+
import openai
23
from typing import Any, Dict, List, Optional, Callable, Awaitable, Union
34
from langtrace.trace_attributes import (
45
LLMSpanAttributes,
@@ -40,6 +41,15 @@
4041
)
4142

4243

44+
def filter_valid_attributes(attributes):
45+
"""Filter attributes where value is not None, not an empty string, and not openai.NOT_GIVEN."""
46+
return {
47+
key: value
48+
for key, value in attributes.items()
49+
if value is not None and value != openai.NOT_GIVEN and value != ""
50+
}
51+
52+
4353
def images_generate(version: str, tracer: Tracer) -> Callable:
4454
"""
4555
Wrap the `generate` method of the `Images` class to trace it.
@@ -57,7 +67,7 @@ def traced_method(
5767
**get_extra_attributes(), # type: ignore
5868
}
5969

60-
attributes = LLMSpanAttributes(**span_attributes)
70+
attributes = LLMSpanAttributes(**filter_valid_attributes(span_attributes))
6171

6272
with tracer.start_as_current_span(
6373
name=get_span_name(APIS["IMAGES_GENERATION"]["METHOD"]),
@@ -118,7 +128,7 @@ async def traced_method(
118128
**get_extra_attributes(), # type: ignore
119129
}
120130

121-
attributes = LLMSpanAttributes(**span_attributes)
131+
attributes = LLMSpanAttributes(**filter_valid_attributes(span_attributes))
122132

123133
with tracer.start_as_current_span(
124134
name=get_span_name(APIS["IMAGES_GENERATION"]["METHOD"]),
@@ -181,7 +191,7 @@ def traced_method(
181191
**get_extra_attributes(), # type: ignore
182192
}
183193

184-
attributes = LLMSpanAttributes(**span_attributes)
194+
attributes = LLMSpanAttributes(**filter_valid_attributes(span_attributes))
185195

186196
with tracer.start_as_current_span(
187197
name=APIS["IMAGES_EDIT"]["METHOD"],
@@ -268,7 +278,7 @@ def traced_method(
268278
**get_extra_attributes(), # type: ignore
269279
}
270280

271-
attributes = LLMSpanAttributes(**span_attributes)
281+
attributes = LLMSpanAttributes(**filter_valid_attributes(span_attributes))
272282

273283
span = tracer.start_span(
274284
name=get_span_name(APIS["CHAT_COMPLETION"]["METHOD"]),
@@ -356,7 +366,7 @@ async def traced_method(
356366
**get_extra_attributes(), # type: ignore
357367
}
358368

359-
attributes = LLMSpanAttributes(**span_attributes)
369+
attributes = LLMSpanAttributes(**filter_valid_attributes(span_attributes))
360370

361371
span = tracer.start_span(
362372
name=get_span_name(APIS["CHAT_COMPLETION"]["METHOD"]),
@@ -438,7 +448,7 @@ def traced_method(
438448
[kwargs.get("input", "")]
439449
)
440450

441-
attributes = LLMSpanAttributes(**span_attributes)
451+
attributes = LLMSpanAttributes(**filter_valid_attributes(span_attributes))
442452

443453
with tracer.start_as_current_span(
444454
name=get_span_name(APIS["EMBEDDINGS_CREATE"]["METHOD"]),
@@ -487,7 +497,7 @@ async def traced_method(
487497
**get_extra_attributes(), # type: ignore
488498
}
489499

490-
attributes = LLMSpanAttributes(**span_attributes)
500+
attributes = LLMSpanAttributes(**filter_valid_attributes(span_attributes))
491501

492502
encoding_format = kwargs.get("encoding_format")
493503
if encoding_format is not None:
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "2.3.14"
1+
__version__ = "2.3.15"

0 commit comments

Comments
 (0)