gpt4 book ai didi

openai-api - OpenAI GPT-3 API : Why do I get only partial completion? 为什么完成中断?

转载 作者:行者123 更新时间:2023-12-02 05:47:17 25 4
gpt4 key购买 nike

我尝试了下面的代码但只得到了部分结果

[{"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)

最佳答案

如果你不设置 max_tokens = 1024 你得到的完成将被切断。再次仔细查看您所指的 tutorial

如果您运行 test.py,OpenAI API 将返回完成:

Light 0 should be red: [{"light_id": 0, "color": {"hue": 0,"saturation": 254, "brightness": 254}},{"light_id": 1, "color": }]

Light 1 should be orange: [{"light_id": 0, "color": {"hue": 0,"saturation": 254, "brightness": 254}},{"light_id": 1, "color":{"hue": 7281, "saturation": 254, "brightness": 254}}]

测试.py

import openai
import os

openai.api_key = os.getenv('OPENAI_API_KEY')

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, max_tokens=1024)
print(completion.choices[0].text)

关于openai-api - OpenAI GPT-3 API : Why do I get only partial completion? 为什么完成中断?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75648132/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com