Skip to content
Open
Show file tree
Hide file tree
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
11 changes: 7 additions & 4 deletions src/openai/types/responses/response_function_web_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@
class ActionSearchSource(BaseModel):
"""A source used in the search."""

type: Literal["url"]
"""The type of source. Always `url`."""
type: Literal["url", "api"]
"""The type of source. One of `url` or `api`."""

url: str
"""The URL of the source."""
name: Optional[str] = None
"""The source name, used for non-URL providers such as internal APIs."""

url: Optional[str] = None
"""The URL of the source when the source type is `url`."""


class ActionSearch(BaseModel):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@
class ActionSearchSource(TypedDict, total=False):
"""A source used in the search."""

type: Required[Literal["url"]]
"""The type of source. Always `url`."""
type: Required[Literal["url", "api"]]
"""The type of source. One of `url` or `api`."""

url: Required[str]
"""The URL of the source."""
name: str
"""The source name, used for non-URL providers such as internal APIs."""

url: str
"""The URL of the source when the source type is `url`."""


class ActionSearch(TypedDict, total=False):
Expand Down
9 changes: 9 additions & 0 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from openai._utils import PropertyInfo
from openai._compat import PYDANTIC_V1, parse_obj, model_dump, model_json
from openai._models import DISCRIMINATOR_CACHE, BaseModel, construct_type
from openai.types.responses.response_function_web_search import ActionSearchSource as ResponseActionSearchSource


class BasicModel(BaseModel):
Expand Down Expand Up @@ -961,3 +962,11 @@ def __getattr__(self, attr: str) -> Item: ...
assert model.a.prop == 1
assert isinstance(model.a, Item)
assert model.other == "foo"


def test_response_function_web_search_source_allows_api_sources() -> None:
source = parse_obj(ResponseActionSearchSource, {"type": "api", "name": "oai-weather"})

assert source.type == "api"
assert source.name == "oai-weather"
assert source.url is None