Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions python/langsmith/wrappers/_openai.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from __future__ import annotations

import functools
Expand Down Expand Up @@ -35,24 +35,33 @@


@functools.lru_cache
def _get_not_given() -> Optional[type]:
def _get_omit_types() -> tuple[type, ...]:
"""Get NotGiven/Omit sentinel types used by OpenAI SDK."""
types = []
try:
from openai._types import NotGiven

return NotGiven
types.append(NotGiven)
except ImportError:
return None
pass
try:
from openai._types import Omit

types.append(Omit)
except ImportError:
pass
return tuple(types)


def _strip_not_given(d: dict) -> dict:
try:
not_given = _get_not_given()
if not_given is None:
omit_types = _get_omit_types()
if not omit_types:
return d
return {
k: v
for k, v in d.items()
if not (isinstance(v, not_given) or (k.startswith("extra_") and v is None))
if not (isinstance(v, omit_types) or (k.startswith("extra_") and v is None))
}
except Exception as e:
logger.error(f"Error stripping NotGiven: {e}")
Expand Down
Loading