MCPcopy
hub / github.com/openai/openai-python / __init__

Method __init__

src/openai/_base_client.py:1479–1523  ·  src/openai/_base_client.py::AsyncAPIClient.__init__
(
        self,
        *,
        version: str,
        base_url: str | URL,
        _strict_response_validation: bool,
        max_retries: int = DEFAULT_MAX_RETRIES,
        timeout: float | Timeout | None | NotGiven = not_given,
        http_client: httpx.AsyncClient | None = None,
        custom_headers: Mapping[str, str] | None = None,
        custom_query: Mapping[str, object] | None = None,
    )

Source from the content-addressed store, hash-verified

1477 _default_stream_cls: type[AsyncStream[Any]] | None = None
1478
1479 def __init__(
1480 self,
1481 *,
1482 version: str,
1483 base_url: str | URL,
1484 _strict_response_validation: bool,
1485 max_retries: int = DEFAULT_MAX_RETRIES,
1486 timeout: float | Timeout | None | NotGiven = not_given,
1487 http_client: httpx.AsyncClient | None = None,
1488 custom_headers: Mapping[str, str] | None = None,
1489 custom_query: Mapping[str, object] | None = None,
1490 ) -> None:
1491 if not is_given(timeout):
1492 class="cm"># if the user passed in a custom http client with a non-default
1493 class="cm"># timeout set then we use that timeout.
1494 class="cm">#
1495 class="cm"># note: there is an edge case here where the user passes in a client
1496 class="cm"># where they've explicitly set the timeout to match the default timeout
1497 class="cm"># as this check is structural, meaning that weclass="st">'ll think they didn't
1498 class="cm"># pass in a timeout and will ignore it
1499 if http_client and http_client.timeout != HTTPX_DEFAULT_TIMEOUT:
1500 timeout = http_client.timeout
1501 else:
1502 timeout = DEFAULT_TIMEOUT
1503
1504 if http_client is not None and not isinstance(http_client, httpx.AsyncClient): class="cm"># pyright: ignore[reportUnnecessaryIsInstance]
1505 raise TypeError(
1506 fclass="st">"Invalid `http_client` argument; Expected an instance of `httpx.AsyncClient` but got {type(http_client)}"
1507 )
1508
1509 super().__init__(
1510 version=version,
1511 base_url=base_url,
1512 class="cm"># cast to a valid type because mypy doesn't understand our type narrowing
1513 timeout=cast(Timeout, timeout),
1514 max_retries=max_retries,
1515 custom_query=custom_query,
1516 custom_headers=custom_headers,
1517 _strict_response_validation=_strict_response_validation,
1518 )
1519 self._client = http_client or AsyncHttpxClientWrapper(
1520 base_url=base_url,
1521 class="cm"># cast to a valid type because mypy doesn't understand our type narrowing
1522 timeout=cast(Timeout, timeout),
1523 )
1524
1525 def is_closed(self) -> bool:
1526 return self._client.is_closed

Callers

nothing calls this directly

Calls 3

is_givenFunction · 0.85
__init__Method · 0.45

Tested by

no test coverage detected