Skip to content

Commit f25acaf

Browse files
committed
fix for older openai libs
1 parent e728250 commit f25acaf

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

sentry_sdk/integrations/openai.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@
2020
from sentry_sdk.tracing import Span
2121

2222
try:
23-
import openai
23+
try:
24+
from openai import NOT_GIVEN
25+
except ImportError:
26+
NOT_GIVEN = None
27+
2428
from openai.resources.chat.completions import Completions, AsyncCompletions
2529
from openai.resources import Embeddings, AsyncEmbeddings
2630

@@ -193,12 +197,13 @@ def _set_input_data(span, kwargs, operation, integration):
193197
}
194198
for key, attribute in kwargs_keys_to_attributes.items():
195199
value = kwargs.get(key)
196-
if value is not openai.NOT_GIVEN and value is not None:
200+
201+
if value is not NOT_GIVEN and value is not None:
197202
set_data_normalized(span, attribute, value)
198203

199204
# Input attributes: Tools
200205
tools = kwargs.get("tools")
201-
if tools is not openai.NOT_GIVEN and tools is not None and len(tools) > 0:
206+
if tools is not NOT_GIVEN and tools is not None and len(tools) > 0:
202207
set_data_normalized(
203208
span, SPANDATA.GEN_AI_REQUEST_AVAILABLE_TOOLS, safe_serialize(tools)
204209
)

0 commit comments

Comments
 (0)