JSON Repair
•减少幻觉的可能性
•使其具备关系感知能力
•您将获得数据类型
- 你能做到的
少样本提示章节中的表 4 展示了如何返回结构化输出的示例。
JSON 修复
虽然以 JSON 格式返回数据具有诸多优势,但也并非没有缺点。JSON 的结构化特性虽然有利于解析和应用,但其所需的标记数量显著多于纯文本,导致处理时间增加和成本上升。此外, JSON 的冗长性很容易耗尽整个输出窗口,当生成因标记限制而突然中断时,这一问题尤为突出。这种截断常常导致 JSON 无效,缺失关键的闭合括号或方括号,使输出无法使用。幸运的是,像 json-repair 库(可在 PyPI 上获取)这样的工具在这些情况下非常宝贵。该库智能地尝试自动修复不完整或格式错误的 JSON 对象,使其成为处理 LLM 生成的 JSON 时的关键助手,尤其是在应对潜在的截断问题时。
全站分卷索引 · 34 卷
- 1Introduction
- 2Prompt engineering
- 3LLM output configuration
- 4Sampling controls
- 5Top-K and top-P
- 6Putting it all together
- 7Prompting techniques
- 8One-shot & few-shot
- 9System, contextual and role prompting
- 10System prompting
- 11Role prompting
- 12Contextual prompting
- 13Step-back prompting
- 14Chain of Thought (CoT)
- 15Self-consistency
- 16Tree of Thoughts (ToT)
- 17ReAct (reason & act)
- 18Automatic Prompt Engineering
- 19Code prompting
- 20Prompts for explaining code
- 21Prompts for translating code
- 22Prompts for debugging and reviewing code
- 23What about multimodal prompting?
- 24Design with simplicity
- 25Be specific about the output
- 26Control the max token length
- 27Experiment with input formats and writing styles
- 28Adapt to model updates
- 29JSON Repair
- 30Working with Schemas
- 31Experiment together with other prompt engineers
- 32CoT Best practices
- 33Summary
- 34Endnotes