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

标签 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

考虑到我确实更改了我的 key 的“MY_KEY”。

但是我得到了:

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

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

最佳答案

发送 POST 请求到 /v1/conversations/text-davinci-003/messages 不会返回你想要的结果,因为这个 URL 没有被 OpenAI API 使用。

这是一个完成消息 Say this is a test

的 cURL 请求示例
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}
  • 创建完成

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

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

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

    POST https://api.openai.com/v1/images/edits
  • 创建图像变体

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

    POST https://api.openai.com/v1/embeddings

OpenAI documentation 中找到更多信息.

关于curl - 测试 OpenAI API 的正确 URL 是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75041247/

相关文章:

c++ - 编译 Curl Visual Studio - 未解析的外部符号

c++ - 如何解决这些 libcurl 链接错误?

mongodb - 将数据发布到 Meteor 的 MongoDB 集合

javascript - 使用 php curl 进行长轮询

python - openai使用python, "text-davinci-002"模型返回长度问题

javascript - OpenAI 没有返回结果?

python - OpenAI Whisper API 错误 : "AttributeError: module ' openai' has no attribute 'Audio' "

javascript - 使用 GPT-3 text-davinci-003 时最大提示 token 不起作用

python - OpenAI 使用 python 返回空模型进行微调

openai-api - 微调 GPT-3 以获得一致的输出格式