Skip to content
Open
Changes from all commits
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
87 changes: 48 additions & 39 deletions portkey_ai/_vendor/openai/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,61 +116,70 @@ class RequestOptions(TypedDict, total=False):


# Sentinel class used until PEP 0661 is accepted
class NotGiven:
"""
For parameters with a meaningful None value, we need to distinguish between
the user explicitly passing None, and the user not passing the parameter at
all.
# Use external openai's NotGiven/Omit if available for compatibility with libraries
# that use the standard openai package (e.g., pydantic-ai, langchain)
try:
from openai._types import NotGiven, Omit, NOT_GIVEN

User code shouldn't need to use not_given directly.
# External openai only exports NOT_GIVEN, not the lowercase not_given
not_given = NOT_GIVEN
# External openai doesn't export lowercase omit, create from class
omit = Omit()
except ImportError:
# Fall back to defining our own (for standalone use without openai installed)
Comment on lines 123 to +129
Copy link

Copilot AI Nov 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Creating a new instance of Omit() in line 127 may not maintain compatibility if the external openai package uses a singleton pattern for omit. Consider checking if the external package exports omit as a module-level constant and using that instead of creating a new instance.

Suggested change
User code shouldn't need to use not_given directly.
# External openai only exports NOT_GIVEN, not the lowercase not_given
not_given = NOT_GIVEN
# External openai doesn't export lowercase omit, create from class
omit = Omit()
except ImportError:
# Fall back to defining our own (for standalone use without openai installed)
# Try to import the singleton 'omit' if available
try:
from openai._types import omit as _external_omit
omit = _external_omit
except ImportError:
# If not exported, create from class
omit = Omit()
# External openai only exports NOT_GIVEN, not the lowercase not_given
not_given = NOT_GIVEN

Copilot uses AI. Check for mistakes.

For example:
class NotGiven:
"""
For parameters with a meaningful None value, we need to distinguish between
the user explicitly passing None, and the user not passing the parameter at
all.

```py
def create(timeout: Timeout | None | NotGiven = not_given): ...
User code shouldn't need to use not_given directly.

For example:

create(timeout=1) # 1s timeout
create(timeout=None) # No timeout
create() # Default timeout behavior
```
"""
```py
def create(timeout: Timeout | None | NotGiven = not_given): ...

def __bool__(self) -> Literal[False]:
return False

@override
def __repr__(self) -> str:
return "NOT_GIVEN"
create(timeout=1) # 1s timeout
create(timeout=None) # No timeout
create() # Default timeout behavior
```
"""

def __bool__(self) -> Literal[False]:
return False

not_given = NotGiven()
# for backwards compatibility:
NOT_GIVEN = NotGiven()
@override
def __repr__(self) -> str:
return "NOT_GIVEN"

not_given = NotGiven()
# for backwards compatibility:
NOT_GIVEN = NotGiven()

class Omit:
"""
To explicitly omit something from being sent in a request, use `omit`.
class Omit:
"""
To explicitly omit something from being sent in a request, use `omit`.

```py
# as the default `Content-Type` header is `application/json` that will be sent
client.post("/upload/files", files={"file": b"my raw file content"})
```py
# as the default `Content-Type` header is `application/json` that will be sent
client.post("/upload/files", files={"file": b"my raw file content"})

# you can't explicitly override the header as it has to be dynamically generated
# to look something like: 'multipart/form-data; boundary=0d8382fcf5f8c3be01ca2e11002d2983'
client.post(..., headers={"Content-Type": "multipart/form-data"})

# instead you can remove the default `application/json` header by passing omit
client.post(..., headers={"Content-Type": omit})
```
"""
# you can't explicitly override the header as it has to be dynamically generated
# to look something like: 'multipart/form-data; boundary=0d8382fcf5f8c3be01ca2e11002d2983'
client.post(..., headers={"Content-Type": "multipart/form-data"})

def __bool__(self) -> Literal[False]:
return False
# instead you can remove the default `application/json` header by passing omit
client.post(..., headers={"Content-Type": omit})
```
"""

def __bool__(self) -> Literal[False]:
return False

omit = Omit()
omit = Omit()

Omittable = Union[_T, Omit]

Expand Down