我正在尝试使用 Windows CMD 中的 curl 请求测试 GPT-3 API:
curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer MY_KEY" -d "{\"text\": \"is this working\"}" https://api.openai.com/v1/conversations/text-davinci-003/messages
考虑到我确实更改了我的 key 的“MY_KEY”。
但是我得到了:
{
"error": {
"message": "Invalid URL (POST /v1/conversations/text-davinci-003/messages)",
"type": "invalid_request_error",
"param": null,
"code": null
}
}
我还尝试了模型名称为 text-davinci-002
和 text-davinci-001
,但得到了相同的无效 URL 错误。这里的正确网址是什么?我在文档(或 chatGPT 本身)中找不到它。
最佳答案
发送 POST 请求到 /v1/conversations/text-davinci-003/messages
不会返回你想要的结果,因为这个 URL 没有被 OpenAI API 使用。
这是一个完成消息 Say this is a test
curl https://api.openai.com/v1/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{"model": "text-davinci-003", "prompt": "Say this is a test", "temperature": 0, "max_tokens": 7}'
这是 API 将响应的示例:
{
"id": "cmpl-GERzeJQ4lvqPk8SkZu4XMIuR",
"object": "text_completion",
"created": 1586839808,
"model": "text-davinci:003",
"choices": [
{
"text": "This is indeed a test",
"index": 0,
"logprobs": null,
"finish_reason": "length"
}
],
"usage": {
"prompt_tokens": 5,
"completion_tokens": 7,
"total_tokens": 12
}
}
这是 API 路径的完整列表:
相反,您可以使用 OpenAI documentation 中列出的 URL :
列出模型
获取https://api.openai.com/v1/models
检索模型
获取https://api.openai.com/v1/models/{model}
创建完成
POSThttps://api.openai.com/v1/completions
创建编辑
POSThttps://api.openai.com/v1/edits
创建图像
POSThttps://api.openai.com/v1/images/generations
创建图像编辑
POSThttps://api.openai.com/v1/images/edits
创建图像变体
POSThttps://api.openai.com/v1/images/variations
创建嵌入
POSThttps://api.openai.com/v1/embeddings
在 OpenAI documentation 中找到更多信息.
关于curl - 测试 OpenAI API 的正确 URL 是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75041247/