gpt4 book ai didi

python - ChatGPT API - 创建大于 gpt-3.5-turbo token 限制的更长 JSON 响应

转载 作者:行者123 更新时间:2023-12-02 22:46:50 26 4
gpt4 key购买 nike

我有一些 ChatGPT API 用例,但我不知道如何处理。

我正在创建 Python 应用程序,并且我有方法创建带有一些指令和一些数据的请求,以便为 ChatGPT 重写。它看起来像这样(指令和数据只是本示例中的一些示例):

openai.ChatCompletion.create(
model="gpt-3.5-turbo",
temperature=0.6,
messages=[
{
"role": "system",
"content": """
You are journalist who creates title and article content based on
the provided data. You also choose category from list: World,
Technology, Health and create 3 tags for article.
Your response is always just JSON which looks like this example
structure:
{
"title": {{insert created title}},
"category": {{insert category}}
"content": {{insert article content}}
"tags": {{insert tags as list of strings}}
}
"""
},
{
"role": "user",
"content": """
Title and article content to rewrite:
title: {}
content: {}
""".format(title, content)
}
]
)

提供的文章内容可能非常长,如果是这样并且达到模型限制,那么我的响应有时是好的 JSON,创建的内容非常短,有时它只是损坏的 JSON,因为由于 token 限制,内容尚未完成。

我已尝试将响应传递给另一个请求,但仍达到限制。

最佳答案

尝试为 GPT 提供一个缩小的 JSON 示例,即,

{"role":"user","content":""} 

而不是

{
"role": "user",
"content": ""
}

这样,GPT 就不会因为给您不必要的空格和换行符而耗尽 token 。

否则,按字段属性分解 JSON 并发出单独的完成请求。单独获取每个属性后,您可以自己形成正确的 JSON 对象。

最后一个选项:使用 GPT-4

关于python - ChatGPT API - 创建大于 gpt-3.5-turbo token 限制的更长 JSON 响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76261677/

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