# 发出请求

您可以将以下命令粘贴到终端中，以运行您的第一个API请求。确保将$ OPENAI\_API\_KEY替换为您的秘密API密钥。

```sh
curl https://api.openai.com/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -d '{
     "model": "gpt-3.5-turbo",
     "messages": [{"role": "user", "content": "Say this is a test!"}],
     "temperature": 0.7
   }'
```

此请求查询`gpt-3.5-turbo`模型以完成从“Say this is a test”开始的文本。您应该收到一个类似于以下内容的响应：

```json
{
   "id":"chatcmpl-abc123",
   "object":"chat.completion",
   "created":1677858242,
   "model":"gpt-3.5-turbo-0301",
   "usage":{
      "prompt_tokens":13,
      "completion_tokens":7,
      "total_tokens":20
   },
   "choices":[
      {
         "message":{
            "role":"assistant",
            "content":"\n\nThis is a test!"
         },
         "finish_reason":"stop",
         "index":0
      }
   ]
}
```

现在，您已经生成了您的第一个聊天完成。我们可以看到`finish_reason`是`stop`，这意味着API返回了模型生成的完整完成。在上面的请求中，我们只生成了一条消息，但您可以将n参数设置为生成多个消息选项。在此示例中，`gpt-3.5-turbo`被用于更传统的<mark style="color:green;">**文本完成任务**</mark>。该模型也经过了<mark style="color:green;">**聊天应用程序**</mark>的优化。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.luojixiangliang.com/reference/openai-api-can-kao-wen-dang/fa-chu-qing-qiu.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
