2

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

链接:-文本生成 API

代码

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:必须提供“引擎”参数才能创建 <class 'openai.api_resources.completion.Completion'>

我正在使用 python 3.7.6

4

2 回答 2

1

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

请更改model = "davinci"engine = "davinci" ,您应该一切顺利。

于 2021-01-25T06:44:39.123 回答
0

如果您收到错误代码:

...
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'])
于 2022-01-01T15:57:08.500 回答