|
26 | 26 |
|
27 | 27 | try: |
28 | 28 | try: |
29 | | - from openai import NOT_GIVEN |
| 29 | + from openai import NotGiven, Omit |
30 | 30 | except ImportError: |
31 | | - NOT_GIVEN = None |
| 31 | + NotGiven = None |
32 | 32 |
|
33 | 33 | from openai.resources.chat.completions import Completions, AsyncCompletions |
34 | 34 | from openai.resources import Embeddings, AsyncEmbeddings |
@@ -211,12 +211,12 @@ def _set_input_data(span, kwargs, operation, integration): |
211 | 211 | for key, attribute in kwargs_keys_to_attributes.items(): |
212 | 212 | value = kwargs.get(key) |
213 | 213 |
|
214 | | - if value is not NOT_GIVEN and value is not None: |
| 214 | + if value is not None and _is_given(value): |
215 | 215 | set_data_normalized(span, attribute, value) |
216 | 216 |
|
217 | 217 | # Input attributes: Tools |
218 | 218 | tools = kwargs.get("tools") |
219 | | - if tools is not NOT_GIVEN and tools is not None and len(tools) > 0: |
| 219 | + if tools is not None and _is_given(tools) and len(tools) > 0: |
220 | 220 | set_data_normalized( |
221 | 221 | span, SPANDATA.GEN_AI_REQUEST_AVAILABLE_TOOLS, safe_serialize(tools) |
222 | 222 | ) |
@@ -696,3 +696,15 @@ async def _sentry_patched_responses_async(*args, **kwargs): |
696 | 696 | return await _execute_async(f, *args, **kwargs) |
697 | 697 |
|
698 | 698 | return _sentry_patched_responses_async |
| 699 | + |
| 700 | + |
| 701 | +def _is_given(obj): |
| 702 | + # type: (Any) -> bool |
| 703 | + """ |
| 704 | + Check for givenness safely across different openai versions. |
| 705 | + """ |
| 706 | + if NotGiven is not None and isinstance(obj, NotGiven): |
| 707 | + return False |
| 708 | + if Omit is not None and isinstance(obj, Omit): |
| 709 | + return False |
| 710 | + return True |
0 commit comments