I’m running into a persistent timeout problem when trying to use OpenAI’s API. The error message I get is:
HTTPSConnectionPool(host='api.openai.com', port=443): Read timed out. (read timeout=600)
Here’s my code that’s causing the issue:
def fetch_openai_completion(prompt_text, debug_mode=False):
"""
Send request to OpenAI API and retrieve completion
:param prompt_text: str - input text for the API
:param debug_mode: bool - whether to show raw response
"""
time.sleep(3)
response = openai.Completion.create(
model='text-davinci-003',
temperature=0.7,
prompt=prompt_text,
max_tokens=200,
n=1,
stop=None,
)
if debug_mode:
print(response)
return response.choices[0].text
data_frame['AI_Response'] = data_frame['Survey_Answer'].apply(lambda response:
fetch_openai_completion(
"Based on this survey response [{}],
categorize it into broad themes like support, product,
pricing or similar categories.
Return format: [Category: your_category]
for: '{}'".format(response, response)))
# Clean up results
data_frame['AI_Response'] = data_frame['AI_Response'].apply(lambda result: result.split(':')[1].replace(']',''))
I’ve tried adjusting different settings but the timeout keeps happening. Has anyone dealt with this before? Any suggestions would be helpful.