InvalidRequestError:在调用 openAI API 以生成文本时必须提供“引擎”参数

问题描述

我正在尝试 OpenAI 中给出的这段代码

链接:- API for text generation

代码

import openai

prompt = """We’re releasing an API for accessing new AI models developed by OpenAI. Unlike most AI systems which are designed for one use-case,the API today provides a general-purpose “text in,text out” interface,allowing users to try it on virtually any English language task. You can Now request access in order to integrate the API into your product,develop an entirely new application,or help us explore the strengths and limits of this technology."""

response = openai.Completion.create(model="davinci",prompt=prompt,stop="\n",temperature=0.9,max_tokens=100)

print(response)

我收到一个错误

错误

"必须提供一个 'engine' 参数来创建一个 %s" % cls,"engine"。 openai.error.InvalidRequestError:必须提供一个“引擎”参数来创建一个

我使用的是 python 3.7.6

解决方法

您似乎将引擎参数与模型参数混淆了。请查看此文档以了解正确的调用方式:https://beta.openai.com/docs/developer-quickstart/python-bindings

请将 model = "davinci" 改为 engine = "davinci" 你应该没事了。