国内环境运行openapi库

代码如下,直接运行会报错,

from openai import OpenAI

client = OpenAI(api_key = "") // 这里填入自己的API_KEY,在openapi官网帐号上有

# Prompt for the conversation

response = client.chat.completions.create(  
  model="gpt-3.5-turbo",
  messages=[
    {"role": "system", "content": "You are a helpful assistant."},
    {"role": "user", "content": "Who won the world series in 2020?"},
    {"role": "assistant", "content": "The Los Angeles Dodgers won the World Series in 2020."},
    {"role": "user", "content": "Where was it played?"}
  ]
)

print(completion.choices[0].message.content)  

本人通常使用Clash软件翻墙,sock5代理,openai库最好直接使用http代理,所以需要将sock5代理转换成http代理

sudo apt-get install privoxy // 安装 privoxy

sudo vim /etc/privoxy/config // 变更配置  
在里面添加:
# 其中forward-socks5 是当前clash监听的sock5代理
# listen-address 是转化后http代理地址 

forward-socks5   /               127.0.0.1:7890 .  
listen-address localhost:8118  

本地终端直接设置http代理

export https_proxy=http://localhost:8118  
export http_proxy=http://localhost:8118  

继续运行上述代码

openai.RateLimitError: Error code: 429 - {'error': {'message': 'You exceeded your current quota, please check your plan and billing details. For more information on this error, read the docs: https://platform.openai.com/docs/guides/error-codes/api-errors.', 'type': 'insufficient_quota', 'param': None, 'code': 'insufficient_quota'}}  

说要已经调用成功,但是没有充值