| 394 | |
| 395 | |
| 396 | class AsyncOpenPipeApi: |
| 397 | def __init__( |
| 398 | self, |
| 399 | *, |
| 400 | base_url: typing.Optional[str] = None, |
| 401 | environment: OpenPipeApiEnvironment = OpenPipeApiEnvironment.DEFAULT, |
| 402 | token: typing.Union[str, typing.Callable[[], str]], |
| 403 | timeout: typing.Optional[float] = 240, |
| 404 | httpx_client: typing.Optional[httpx.AsyncClient] = None, |
| 405 | ): |
| 406 | self._client_wrapper = AsyncClientWrapper( |
| 407 | base_url=_get_base_url(base_url=base_url, environment=environment), |
| 408 | token=token, |
| 409 | httpx_client=httpx.AsyncClient(timeout=timeout) if httpx_client is None else httpx_client, |
| 410 | ) |
| 411 | |
| 412 | async def check_cache( |
| 413 | self, |
| 414 | *, |
| 415 | requested_at: float, |
| 416 | req_payload: typing.Optional[typing.Any] = OMIT, |
| 417 | tags: typing.Optional[typing.Dict[str, str]] = OMIT, |
| 418 | ) -> CheckCacheResponse: |
| 419 | """ |
| 420 | DEPRECATED: we no longer support prompt caching. |
| 421 | |
| 422 | Parameters: |
| 423 | - requested_at: float. Unix timestamp in milliseconds |
| 424 | |
| 425 | - req_payload: typing.Optional[typing.Any]. |
| 426 | |
| 427 | - tags: typing.Optional[typing.Dict[str, str]]. Extra tags to attach to the call for filtering. Eg { "userId": "123", "promptId": "populate-title" } |
| 428 | """ |
| 429 | _request: typing.Dict[str, typing.Any] = {"requestedAt": requested_at} |
| 430 | if req_payload is not OMIT: |
| 431 | _request["reqPayload"] = req_payload |
| 432 | if tags is not OMIT: |
| 433 | _request["tags"] = tags |
| 434 | _response = await self._client_wrapper.httpx_client.request( |
| 435 | "POST", |
| 436 | urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "check-cache"), |
| 437 | json=jsonable_encoder(_request), |
| 438 | headers=self._client_wrapper.get_headers(), |
| 439 | timeout=240, |
| 440 | ) |
| 441 | if 200 <= _response.status_code < 300: |
| 442 | return pydantic.parse_obj_as(CheckCacheResponse, _response.json()) # type: ignore |
| 443 | try: |
| 444 | _response_json = _response.json() |
| 445 | except JSONDecodeError: |
| 446 | raise ApiError(status_code=_response.status_code, body=_response.text) |
| 447 | raise ApiError(status_code=_response.status_code, body=_response_json) |
| 448 | |
| 449 | async def create_chat_completion( |
| 450 | self, |
| 451 | *, |
| 452 | req_payload: typing.Optional[CreateChatCompletionRequestReqPayload] = OMIT, |
| 453 | model: typing.Optional[str] = OMIT, |