您可以通过以下方式在Postman中进行POST设置,以使其正常工作:
Leave all items in the Params tab empty
In the Authorization tab, paste your OpenAI API token as the Type Bearer Token (as you likely already did)
In the Headers tab, add key "Content-Type" with value "application/json"
In the Body tab, switch to Raw, and add e.g.
{
"model":"text-davinci-002",
"prompt":"Albert Einstein was"
}
Hit Send. You'll get back the completions for your prompt.
请注意,您也可以将模型添加到Post URL中,例如https://api.openai.com/v1/engines/text-davinci-002/completions
虽然上述方法可行,但可能没有充分利用Postman UI的功能--毕竟,我们正在原始编辑JSON,而不是利用好的键值输入框。如果您找到了如何使用后者的方法,请告诉我们。
https://api.openai.com/v1/engines/
终端已被弃用。 - Rubén您需要注意接口的请求类型。如果使用GET请求POST,也会报错。
来自
response = openai.Completion.create(
engine="text-davinci-003",
prompt=prompt,
max_tokens=100,
n=1,
stop=None,
temperature=0.3,
presence_penalty=2
)
answer = response.choices[0].text.strip()
至
messages=dict(role="user", content=prompt)
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[messages],
max_tokens=100,
n=1,
stop=None,
temperature=0.3,
presence_penalty=2
)
answer = response['choices'][0]['message']['content']
POST
,而不是GET
。现在一切都好了! - Jonathan