InvalidRequestError: Must provide an 'engine' parameter while invoking openAI API for text generation

InvalidRequestError: Must provide an 'engine' parameter while invoking openAI API for text generation

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

Link:- 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)

我收到一个错误

错误

"Must provide an 'engine' parameter to create a %s" % cls, "engine". openai.error.InvalidRequestError: Must provide an 'engine' parameter to create a <class 'openai.api_resources.completion.Completion'>

我正在使用 python 3.7.6

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

请将model = "davinci"改为engine = "davinci" 你应该可以开始了。

如果您收到错误代码:

...
InvalidRequestError: Engine not found

一个可能的问题是您的帐户设置不允许您访问该引擎。例如,嵌入引擎仅适用于“私人测试版”。您可能需要为您的帐户请求访问它。 以下代码可能会为您的帐户提供可用的引擎:

import openai

openai.api_key = your_openai_api_key

data = openai.Engine.list() for eng in data['data']:
    print(eng['id'])