我运行以下代码时,一直出现如下错误:
请求超时:HTTPSConnectionPool(host='api.openai.com', port=443):读取超时。(读取超时=600)
def generate_gpt3_response(user_text, print_output=False):
"""
Query OpenAI GPT-3 for the specific key and get back a response
:type user_text: str the user's text to query for
:type print_output: boolean whether or not to print the raw output JSON
"""
time.sleep(5)
completions = ai.Completion.create(
engine='text-davinci-003', # Determines the quality, speed, and cost.
temperature=0.5, # Level of creativity in the response
prompt=user_text, # What the user typed in
max_tokens=150, # Maximum tokens in the prompt AND response
n=1, # The number of completions to generate
stop=None, # An optional setting to control response generation
)
# Displaying the output can be helpful if things go wrong
if print_output:
print(completions)
# Return the first choice's text
return completions.choices[0].text
df_test['GPT'] = df_test['Q20'].apply(lambda x: \
generate_gpt3_response\
("I am giving you the answer of respondents \
in the format [Q20], \
give me the Broader topics like customer service, technology, satisfaction\
or the related high level topics in one word in the \
format[Topic: your primary topic] for the text '{}' ".format(x)))
# result
df_test['GPT'] = df_test['GPT'].apply(lambda x: (x.split(':')[1]).replace(']',''))
我尝试修改参数,但错误仍然发生。
有人经历过相同的过程吗?
提前感谢。