The timeout
parameter is an optional parameter that can be passed to the create
method.
Inside the method, the timeout
parameter is extracted from the kwargs
dictionary using the pop
. If timeout
isn’t provided, its default value will be None
class ChatCompletion(EngineAPIResource):
engine_required = False
OBJECT_NAME = "chat.completions"
@classmethod
def create(cls, *args, **kwargs):
"""
Creates a new chat completion for the provided messages and parameters.
See https://platform.openai.com/docs/api-reference/chat/create
for a list of valid parameters.
"""
start = time.time()
timeout = kwargs.pop("timeout", None)
while True:
try:
return super().create(*args, **kwargs)
except TryAgain as e:
if timeout is not None and time.time() > start + timeout:
raise
util.log_info("Waiting for model to warm up", error=e)
However, after this line:
timeout = kwargs.pop("timeout", None)
the timeout
parameter no longer exists in the kwargs
dictionary because pop
removes the key from the dictionary.
Here's super().create()
@classmethod
def create(
cls,
api_key=None,
api_base=None,
api_type=None,
request_id=None,
api_version=None,
organization=None,
**params,
):
(
deployment_id,
engine,
timeout,
stream,
headers,
request_timeout,
typed_api_type,
requestor,
url,
params,
) = cls.__prepare_create_request(
api_key, api_base, api_type, api_version, organization, **params
)
response, _, api_key = requestor.request(
"post",
url,
params=params,
headers=headers,
stream=stream,
request_id=request_id,
request_timeout=request_timeout,
)
if stream:
# must be an iterator
assert not isinstance(response, OpenAIResponse)
return (
util.convert_to_openai_object(
line,
api_key,
api_version,
organization,
engine=engine,
plain_old_data=cls.plain_old_data,
)
for line in response
)
else:
obj = util.convert_to_openai_object(
response,
api_key,
api_version,
organization,
engine=engine,
plain_old_data=cls.plain_old_data,
)
if timeout is not None:
obj.wait(timeout=timeout or None)
return obj
To conclude:
- The
timeout
parameter is popped from kwargs
in ChatCompletion.create()
, so it won’t be passed to super().create()
via **kwargs
.
- The
request_timeout
parameter, if provided to ChatCompletion.create()
, will be passed to super().create()
via **kwargs
.