我尝试了以下代码,但只得到了部分结果,例如
[{"light_id": 0, "color
Run Code Online (Sandbox Code Playgroud)
我期待本页建议的完整 JSON:
https://medium.com/@richardhayes777/using-chatgpt-to-control-hue-lights-37729959d94f
import json
import os
import time
from json import JSONDecodeError
from typing import List
import openai
openai.api_key = "xxx"
HEADER = """
I have a hue scale from 0 to 65535.
red is 0.0
orange is 7281
yellow is 14563
purple is 50971
pink is 54612
green is 23665
blue is 43690
Saturation is from 0 to 254
Brightness is from 0 to 254
Two JSONs should be returned in a list. Each …
Run Code Online (Sandbox Code Playgroud) 当收到来自 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)