I often got a timeout 600s error when using the Chat completions API. So I found out that if you put a request_timeout as a parameter it would stop the request after a certain amount of time. And this worked great until I had to update the SDK version from 0.28.1 to 1.2.2. Now the request_timeout
parameter is gone and there is only the timeout
parameter. But from my experience using timeout
doesn’t stop the request even after it goes past the custom time set. This is what my previous request looked like:
response = openai.ChatCompletion.create(
model='gpt-3.5-turbo-1106',
messages=[
{"role": "system",
"content":
"I will give you a sentence. I want you to summarize the topic of the sentence in 3 words."
"These 3 words will be used to search for an image to fit the sentence so make sure the words make sense to the meaning of the sentence."
f"Answer by writing the 3 words only."
},
{"role": "user",
"content": f"This is the sentence: '{sentence}'."},
],
# temperature=0.3,
request_timeout=90,
)
message = response.choices[0]['message']
# Get the content from the message
content = message['content']
And this is what it looks like now:
try:
completion = client.chat.completions.create(
model='gpt-3.5-turbo-1106',
messages=[
{"role": "system",
"content":
"I will give you a sentence. I want you to summarize the topic of the sentence in 3 words."
"These 3 words will be used to search for an image to fit the sentence so make sure the words make sense to the meaning of the sentence."
f"Answer by writing the 3 words only."
},
{"role": "user",
"content": f"This is the sentence: '{sentence}'."},
],
# temperature=0.3,
timeout=90,
)
message = completion.choices[0].message
# Get the content from the message
content = message.content