InvalidRequestError: Must provide an 'engine' parameter while invoking openAI API for text generation
Question:
I was trying this code given in OpenAI.
Link:- API for text generation
Code
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)
I’m getting an error
Error
"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’>
I’m using python 3.7.6
Answers:
It seems you have confused the engine parameter with the model parameter. Please have a look at this documentation for the correct way to call: https://beta.openai.com/docs/developer-quickstart/python-bindings
Please change model = "davinci"
to engine = "davinci"
and you should be good to go.
If you get the error code:
...
InvalidRequestError: Engine not found
One possible problem could be your account setting does not offer you access to the engine. For example, embedding engines are only available for "private beta." You may need to request access to it for your account.
The following code may get you the available engines to your account:
import openai
openai.api_key = your_openai_api_key
data = openai.Engine.list() for eng in data['data']:
print(eng['id'])
I was trying this code given in OpenAI.
Link:- API for text generation
Code
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)
I’m getting an error
Error
"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’>
I’m using python 3.7.6
It seems you have confused the engine parameter with the model parameter. Please have a look at this documentation for the correct way to call: https://beta.openai.com/docs/developer-quickstart/python-bindings
Please change model = "davinci"
to engine = "davinci"
and you should be good to go.
If you get the error code:
...
InvalidRequestError: Engine not found
One possible problem could be your account setting does not offer you access to the engine. For example, embedding engines are only available for "private beta." You may need to request access to it for your account.
The following code may get you the available engines to your account:
import openai
openai.api_key = your_openai_api_key
data = openai.Engine.list() for eng in data['data']:
print(eng['id'])