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
25 changes: 25 additions & 0 deletions src/openai/_base_client.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from __future__ import annotations
# openai/_exceptions.py


import sys
import json
Expand Down Expand Up @@ -67,6 +69,29 @@
AsyncAPIResponse,
extract_response_type,
)
# openai/_exceptions.py
class ReadTimeoutError(OpenAIError):
"""Raised when the server takes too long to send a response."""
pass
import httpx
from ._exceptions import ReadTimeoutError

class BaseClient:
def _request(self, method, path, **kwargs):
try:
return self._http_client.request(method, path, **kwargs)
except httpx.ReadTimeout as e:
raise ReadTimeoutError(
f"Read timeout occurred while waiting for response from {path}. "
f"Consider increasing the timeout or using retries."
) from e
class BaseClient:
def __init__(self, *, timeout: float = 30.0, max_retries: int = 0, **kwargs):
self._timeout = timeout
self._max_retries = max_retries
super().__init__(**kwargs)
self._http_client = httpx.Client(timeout=self._timeout)

from ._constants import (
DEFAULT_TIMEOUT,
MAX_RETRY_DELAY,
Expand Down