OpenAI GPT-3 API 错误:“请求超时”

ops*_*psv 9 python openai-api gpt-3

我不断收到如下错误

Request timed out: HTTPSConnectionPool(host='api.openai.com', port=443): Read timed out. (read timeout=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
Run Code Online (Sandbox Code Playgroud)
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(']',''))
Run Code Online (Sandbox Code Playgroud)

我尝试修改参数,但仍然出现错误。

有人经历过同样的过程吗?

提前致谢。

Rok*_*nko 3

正如OpenAI官方文档中所述:

错误Timeout表明您的请求完成时间过长,我们的服务器关闭了连接。这可能是由于网络问题、我们的服务负载过重或需要更多处理时间的复杂请求造成的。

如果您遇到Timeout错误,请尝试以下步骤:

  • 等待几秒钟,然后重试您的请求。有时,网络拥塞或我们服务的负载可能会减少,您的请求可能会在第二次尝试时成功。
  • 检查您的网络设置并确保您拥有稳定且快速的互联网连接。您可能需要切换到不同的网络、使用有线连接或减少使用带宽的设备或应用程序的数量。
  • 如果问题仍然存在,请查看我们的持续错误后续步骤部分。