发出请求
您可以将下面的命令粘贴到您的终端中以运行您的第一个 API 请求。确保替换YOUR_API_KEY
为您的在GPT WEB API后台生成的令牌(sk-xxx)。
curl https://api.pro365.top/v1/chat/completions \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer YOUR_API_KEY' \
-d '{
"model": "gpt-3.5-turbo",
"messages": [{"role": "user", "content": "Say this is a test!"}],
"temperature": 0.7
}'
或者Powershell:
$headers = @{
"Content-Type" = "application/json"
"Authorization" = "Bearer YOUR_API_KEY"
}
$body = @{
"model" = "gpt-3.5-turbo"
"messages" = @(@{ "role" = "user"; "content" = "Say this is a test!" })
"temperature" = 0.7
} | ConvertTo-Json
$response = Invoke-WebRequest -Uri "https://api.pro365.top/v1/chat/completions" -Method Post -Headers $headers -Body $body
$response.Content
此请求查询模型以完成以提示“ Say this is a testgpt-3.5-turbo
”开头的文本。您应该会收到类似于以下内容的响应:
1 {
2 "id":"chatcmpl-abc123",
3 "object":"chat.completion",
4 "created":1677858242,
5 "model":"gpt-3.5-turbo",
6 "usage":{
7 "prompt_tokens":13,
8 "completion_tokens":5,
9 "total_tokens":18
10 },
11 "choices":[
12 {
13 "message":{
14 "role":"assistant",
15 "content":"\n\nThis is a test!"
16 },
17 "finish_reason":"stop",
18 "index":0
19 }
20 ]
21 }
现在你已经生成了你的第一个聊天完成。我们可以看到finish_reason
isstop
这意味着 API 返回了模型生成的完整完成。在上面的请求中,我们只生成了一条消息,但是你可以设置参数n
来生成多条消息选择。在这个例子中,gpt-3.5-turbo
更多的是用于传统的文本完成任务。该模型还针对聊天应用程序进行了优化。
修改于 8 个月前