测试 OpenAI API 的正确 URL 是什么?

Tom*_*ito 0 curl openai-api gpt-3

我正在尝试在 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
Run Code Online (Sandbox Code Playgroud)

鉴于我确实更改了我的密钥“MY_KEY”。

但我得到了:

{
  "error": {
    "message": "Invalid URL (POST /v1/conversations/text-davinci-003/messages)",
    "type": "invalid_request_error",
    "param": null,
    "code": null
  }
}
Run Code Online (Sandbox Code Playgroud)

我还尝试将模型名称命名为text-davinci-002text-davinci-001,但得到相同的无效 URL 错误。这里正确的网址是什么?我在文档(或 chatGPT 本身)中找不到它。

joe*_*nni 9

发送 POST 请求/v1/conversations/text-davinci-003/messages不会返回您想要的结果,因为 OpenAI API 不使用此 URL。

以下是完成消息的 cURL 请求示例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}'
Run Code Online (Sandbox Code Playgroud)

这是 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
    }
}
Run Code Online (Sandbox Code Playgroud)

这是 API 路径的完整列表:

相反,您可以使用OpenAI 文档中列出的 URL :

  • 列出型号

    得到https://api.openai.com/v1/models
  • 检索模型

    得到https://api.openai.com/v1/models/{model}
  • 创建完成

    邮政https://api.openai.com/v1/completions
  • 创建编辑

    邮政https://api.openai.com/v1/edits
  • 创建图像

    邮政https://api.openai.com/v1/images/generations
  • 创建图像编辑

    邮政https://api.openai.com/v1/images/edits
  • 创建图像变化

    邮政https://api.openai.com/v1/images/variations
  • 创建嵌入

    邮政https://api.openai.com/v1/embeddings

更多信息请参见OpenAI 文档

  • 只需要转义 json 上的双引号即可。谢谢! (2认同)