首页 / 开源项目 / 正文
开源项目

Guidance结构化生成库:用JSON Schema约束LLM输出,轻松生成可靠结构化数据

chuanbook chuanbook
发布于 2026 年 10 月 23 日
阅读 约1分钟
浏览 2
评论 0

from guidance import models, gen

lm = models.OpenAI("gpt-3.5-turbo") result = lm + "请生成一个城市名称:" + gen(max_tokens=10) print(result)

schema = {

"type": "object",
"properties": {
    "order_id": {"type": "string", "pattern": "^ORD-\\d{6}$"},
    "status": {"type": "string", "enum": ["待付款", "已发货", "已完成"]},
    "amount": {"type": "number"},
    "remark": {"type": "string"}
},
"required": ["order_id", "status"]

}

赞0
踩0
☆收藏0
版权声明
文章版权声明:除非注明,否则均为ZBLOG原创文章,转载或复制请以超链接形式并注明出处。
分享到
chuanbook

链接已复制到剪贴板