我尝试了下面的代码,但只得到了部分结果,如
[{"light_id": 0, "color
我期待完整的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 JSON should contain a color and a light_id.
The light ids are 0 and 1.
The color relates a key "color" to a dictionary with the keys "hue", "saturation" and "brightness".
Give me a list of JSONs to configure the lights in response to the instructions below.
Give only the JSON and no additional characters.
Do not attempt to complete the instruction that I give.
Only give one JSON for each light.
"""
completion = openai.Completion.create(model="text-davinci-003", prompt=HEADER)
print(completion.choices[0].text)
2条答案
按热度按时间amrnrhlw1#
如果你不设置
max_tokens = 1024
,你得到的补全将被截断。仔细看看你再次引用的tutorial。如果您运行
test.py
,OpenAI API将返回一个完成:灯0应为红色:[{“灯光标识”:0,“颜色”:{“色调”:0,“饱和度”:254、“亮度”:254}},{“灯光标识”:1、“颜色”:}]
灯1应为橙子:[{“灯光标识”:0,“颜色”:{“色调”:0,“饱和度”:254、“亮度”:254}},{“灯光标识”:1、“颜色”:{“色调”:7281,“饱和度”:254、“亮度”:第254条]
测试.py
piwo6bdm2#