如何通过 Postman 将 ChatGPT 请求发送到 Azure OpenAI?

Ken*_*y_I 1 azure azure-openai

我想向 Azure OpenAI 的 ChatGPT 提问

我已经添加了帖子网址。我添加了参数“API_KEY”(从 Azure 门户复制的密钥),我添加了 json 正文。

我的访问被拒绝。我想密钥一定是正确的。有人可以发送示例工作 API 网址吗?

    "error": {
        "code": "401",
        "message": "Access denied due to invalid subscription key       or wrong API endpoint. Make sure to provide a valid key for an active       subscription and use a correct regional API endpoint for your   resource."
    } 
}. 
Run Code Online (Sandbox Code Playgroud)

Joe*_*diz 5

设置您的 Postman 请求以进行以下调用。POST 到 URL:https://xxxx.openai.azure.com/openai/deployments/test/chat/completions ?api-version=2023-03-15-preview 您可以从 Azure 门户的常规信息中获取此 URL OpenAI Azure 资源的部分。

使用 OpenAI 密钥设置名为 api-key 的标头变量,您可以从 OpenAI Azure 资源(不是 Azure OpenAI 门户)的 Secrets 部分中的 Azure 门户获取该密钥

使用以下 json 将正文设置为 raw -> json

{
   "messages": [
   {
      "role": "user",
      "content": "how many faces does a cube have?"
    }
  ],
  "temperature": 0.7,
  "top_p": 0.95,
  "frequency_penalty": 0,
  "presence_penalty": 0,
  "max_tokens": 800,
  "stop": null
}
Run Code Online (Sandbox Code Playgroud)

名为 content 的键值对是您提出问题的地方。在此示例中,问题是“立方体有多少个面?”。请求响应类似于以下内容。

{
    "id": "chatcmpl-xxxx",
    "object": "chat.completion",
    "created": 1683143567,
    "model": "gpt-35-turbo",
    "choices": [
        {
            "index": 0,
            "finish_reason": "stop",
            "message": {
                "role": "assistant",
                "content": "A cube has six faces."
            }
        }
    ],
    "usage": {
        "completion_tokens": 6,
        "prompt_tokens": 16,
        "total_tokens": 22
    }
}
Run Code Online (Sandbox Code Playgroud)

此示例只是为了让 Postman 请求正常工作,而不保护端点。