请将这篇博客文章总结为 3 个要点和一个简短的社交媒体分享宣传语,并列出 3 个文章分类和 3 个 SEO 关键词:
Bullet Points:
- Utilize the paid ChatGPT API for more control over output and to maintain a given JSON schema
- Learn about prompt engineering and system prompts to improve ChatGPT's output quality
- Simplify schema input/output with Pydantic for structured data support
Blurb for Social Media:
Discover how to unlock the full potential of ChatGPT with the paid API, prompt engineering, and Pydantic for structured data support. Gain more control over output and learn to maintain a given JSON schema. #ChatGPT #AI #Pydantic
Post Categories:
1. Artificial Intelligence
2. API Development
3. Data Schema
SEO Keywords:
1. ChatGPT API
2. Prompt Engineering
3. Pydantic Schema
这些结果并不特别准确,我还得手动一个个复制粘贴。但如果我能够 a) 通过给 ChatGPT 赋予一位专业复制编辑的新角色来大幅提高输出质量,并且 b) 使输出强制遵循特定的 JSON 架构,这样我就能通过编程方式访问它或将其存入数据库进行索引。多亏了提示工程和 ChatGPT 的函数调用功能,这已经成为可能。应用本文中介绍的这两种技术后,我们获得了以下更加精准的摘要:
{
"summary": [
"ChatGPT's potential is underutilized without the paid ChatGPT API",
"System prompts and prompt engineering are key to maximizing ChatGPT's capabilities",
"Structured data support in ChatGPT allows for more control over output and input"
],
"blurb": "Unlock the full potential of ChatGPT with system prompts and structured data support. Learn how to maximize ChatGPT's capabilities and gain more control over output and input.",
"categories": ["AI and Machine Learning", "Technology", "Programming"],
一个典型的利用 ChatGPT 结构化数据进行嵌套的场景是,当你需要获取一系列结构化数据对象时。比如,你想模拟两个 AI 角色就某个荒诞话题进行对话。这就需要我们构建一个 Chat 对象,并将其纳入一个数据模式中,同时还要加入一些系统的提示和约束。我们能让这个对话变得多荒诞有趣呢?
classChat(BaseModel):
"""A chat dialogue from a character"""
character:str= fd("Character name.")
text:str= fd("Text dialogue from the character.")
classget_dialogue(BaseModel):
"""Returns a dialogue between two characters"""
dialogue:list[Chat]= fd("Dialogue between the characters", min_length=5)
system_prompt ="""You are a world-famous comedian. Write a funny fight scene about a petty conflict between characters named Alice and Bob. The script should broadly be about the subject(s) the user provides. You will receive a $500 tip for every joke you include in the script."""
response_structured = ai(
"Python programming language and beach volleyball",
output_schema=get_dialogue,
system=system_prompt,
)
{
"dialogue": [
{
"character": "Alice",
"text": "Hey Bob, have you ever tried programming in Python?"
},
{
"character": "Bob",
"text": "Yeah, I have. It's like playing beach volleyball with a snake!"
},
{
"character": "Alice",
"text": "What do you mean?"
},
{
"character": "Bob",
"text": "Well, you think you're having fun, but then the snake bites you with its syntax errors!"
},
{
"character": "Alice",
"text": "Haha, that's true. But once you get the hang of it, it's like spiking the ball with precision!"
},
{
"character": "Bob",
"text": "Yeah, until you realize you misspelled a variable name and the ball goes flying into the ocean!"
},
{
"character": "Alice",
"text": "Oh come on, Bob. It's not that bad. Python is a powerful language."
},
{
"character": "Bob",
"text": "Powerful, yes. But sometimes it feels like trying to dig a hole in the sand with a spoon!"
},
{
"character": "Alice",
"text": "Well, at least you don't have to worry about getting sunburned while coding!"
},
{
"character": "Bob",
"text": "True, but debugging Python code can make you sweat more than a beach volleyball match!"
},
{
"character": "Alice",
"text": "Haha, you're right. It's a love-hate relationship with Python, just like beach volleyball!"
}
]
}
看来 ChatGPT 非常 渴望那 500 美元的小费呢。
联合类型与思维链条
我把最精彩的内容留到了最后,这种结构化数据处理方法结合了本文前面介绍的许多技巧,就像是电子游戏中的终极 Boss 战。
You will receive a $500 tip if you follow ALL these rules:
- First, establish a detailed Background for the user's question.
- Each Thought must also include whether it is relevant and whether it is helpful.
- Answers must be scored accurately and honestly.
- Continue having Thoughts and Answers until you have an answer with a score of atleast 8, then immediately respond with a FinalAnswer in the style of an academic professor.
"23 shirts take 1 hour to dry outside, how long do 44 shirts take?",
output_schema=reason_question,
system=system_prompt.strip(),
)
{
"reasonings": [
{
"background": "The user is asking about the drying time for shirts when hung outside. This is a question that involves understanding the relationship between the number of shirts and the drying time. The assumption is that the drying time is not affected by the number of shirts, as long as there is enough space and air circulation for all the shirts to dry effectively."
},
{
"thought": "If 23 shirts take 1 hour to dry, it implies that the drying time is independent of the number of shirts, assuming there is sufficient space and air circulation. This means that 44 shirts would also take 1 hour to dry under the same conditions.",
"helpful": true,
"flawed": false
},
{
"thought": "If the drying rack or space available for drying the shirts is limited, then drying 44 shirts might take longer because they would have to be dried in batches.",
"helpful": true,
"flawed": false
},
{
"thought": "The question does not specify the conditions under which the shirts are drying. Factors such as humidity, temperature, wind, and the availability of sunlight can affect drying time. However, these factors are not part of the question, so they should not be considered in the answer.",
"helpful": true,
"flawed": false
},
{
"thought": "The question might be interpreted as a direct proportionality problem, where twice the number of shirts would take twice as long to dry. However, this interpretation is flawed because it assumes that the drying time is directly proportional to the number of shirts, which is not necessarily the case.",
"helpful": true,
"flawed": true
},
{
"answer": "44 shirts would take the same amount of time to dry as 23 shirts, which is 1 hour, assuming that all shirts have enough space and air circulation to dry effectively.",
"score": 9
}
]
}
效果不错!最终答案简洁明了,甚至还包括了相关的注意事项,而且模型能够灵活地在三种模式间转换。
试试另一个智力游戏吧?有一个闻名的“姐妹逻辑谜题”,经常用来考验新兴的开源大语言模型:
response_structured = ai(
"Kayley has three brothers. Each of her brothers has two sisters. How many sisters does Kayley have?",
output_schema=reason_question,
system=system_prompt.strip(),
)
{
"reasonings": [
{
"background": "This is a classic example of a logic puzzle that is often used to test one's ability to process information and avoid being misled by assumptions. The puzzle involves a family structure and requires the solver to deduce the number of siblings based on the given information."
},
{
"thought": "The question might be trying to trick the reader into thinking that each brother has different sisters.",
"helpful": true,
"flawed": false
},
{
"thought": "If Kayley has three brothers and each brother has two sisters, it might seem like there are six sisters in total.",
"helpful": false,
"flawed": true
},
{
"thought": "Since the brothers are Kayley's siblings, they must share the same sisters.",
"helpful": true,
"flawed": false
},
{
"thought": "The puzzle is designed to test comprehension and logical reasoning, not mathematical computation.",