求问始皇的oaipro如何通过官方OpenAI库使用

刚刚第一次充值完oaipro,但是发现不会通过python调用,按照Openai的官方教程尝试了下面的代码

from openai import OpenAI

client = OpenAI(
    api_key="",
    base_url="https://api.openai.com"
)


completion = client.chat.completions.create(
  model="gpt-3.5-turbo",
  messages=[
    {"role": "system", "content": "You are a poetic assistant, skilled in explaining complex programming concepts with creative flair."},
    {"role": "user", "content": "Compose a poem that explains the concept of recursion in programming."}
  ]
)
print(completion.choices[0].message)

但是会出现下面的报错信息:

NotFoundError: Error code: 404 - {'error': {'type': 'invalid_request_error', 'code': 'unknown_url', 'message': 'Unknown request URL: POST /chat/completions. Please check the URL for typos, or see the docs at https://platform.openai.com/docs/api-reference/.', 'param': None}}
2 个赞

base_url填中转的url,api key也是填中转的api key就行了

但是oaipro不是说直接代理官方接口吗?https://api.openai.com
我加/v1和不加好像这代码都还是报错

在其他帖子看到了解决方案,确实是base_url的问题,应该用api_base = "https://api.oaipro.com/v1"

From 快问快答 to 开发调优

1 个赞