When receiving a response from OpenAI's text-davinci-003
model, I was able to extract the text from the response with the following PHP code:
$response = $response->choices[0]->text;
Here was the text-davinci-003
response code:
{
"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
}
}
I am now trying to alter my code to work with the recently released gpt-3.5-turbo
model which returns the response slightly differently:
{
"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"
}],
"usage": {
"prompt_tokens": 9,
"completion_tokens": 12,
"total_tokens": 21
}
}
My question is, how can I alter the code:
$response = $response->choices[0]->text;
...so that it can grab the content of the response message?