想尝试一下使用openAI的API_key,用python运行下列程序
import os
import openai
# Set the API key
openai.api_key = os.getenv("OPENAI_API_KEY")
# Define the model and prompt
model_engine = "text-davinci-003"
prompt = "What is the capital of France?"
# Generate a response
completion = openai.Completion.create(
engine=model_engine,
prompt=prompt,
max_tokens=1024,
n=1,
stop=None,
temperature=0.5,
)
# Get the response text
message = completion.choices[0].text
print(message)
开启代理会弹出以下错误:
但如果不开启代理,则连接不到openai服务器:
但好像我在某个帖子中看到使用API可以无视地域限制地调用openai提供的一些功能,我的KEY是刚申请的还未使用过,有6个月5美元的免费使用额度。所以这里显示的连接失败也不知道是什么问题。
请教各位使用过的有无遇到该问题,都是怎么解决的?或者我的设置有问题?