当收到来自 OpenAI 模型的响应时text-davinci-003,我能够使用以下 PHP 代码从响应中提取文本:
$response = $response->choices[0]->text;
Run Code Online (Sandbox Code Playgroud)
这是text-davinci-003响应代码:
{
"id": "cmpl-uqkvlQyYK7bGYrRHQ0eXlWi7",
"object": "text_completion",
"created": 1589478378,
"model": "text-davinci-003",
"choices": [
{
"text": "\n\nThis 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)
我现在尝试更改我的代码以使用最近发布的gpt-3.5-turbo模型,该模型返回的响应略有不同:
{
"id": "chatcmpl-123",
"object": "chat.completion",
"created": 1677652288,
"choices": [{
"index": 0,
"message": {
"role": "assistant",
"content": "\n\nHello there, how may I assist you today?",
},
"finish_reason": "stop"
}], …Run Code Online (Sandbox Code Playgroud)