当前位置: 首页 > news >正文

pydantic定义llm response数据模型

pydantic基于BaseModel定义的数据模型,能通过model_json_schema输出json解读。

示例如下

from pydantic import BaseModelclass semantic_group(BaseModel):semantic_unit:strentities:list[str]relationships:list[str]class text_decomposition(BaseModel):Output:list[semantic_group]class relationship_reconstraction(BaseModel):source:strrelationship:strtarget:strclass elements(BaseModel):title:strdescription:strtext_decomposition.model_json_schema()

输出如下

{'$defs': {'semantic_group': {'properties': {'semantic_unit': {'title': 'Semantic Unit',
     'type': 'string'},
    'entities': {'items': {'type': 'string'},
     'title': 'Entities',
     'type': 'array'},
    'relationships': {'items': {'type': 'string'},
     'title': 'Relationships',
     'type': 'array'}},
   'required': ['semantic_unit', 'entities', 'relationships'],
   'title': 'semantic_group',
   'type': 'object'}},
 'properties': {'Output': {'items': {'$ref': '#/$defs/semantic_group'},
   'title': 'Output',
   'type': 'array'}},
 'required': ['Output'],
 'title': 'text_decomposition',
 'type': 'object'}

reference

---

Pydantic 模型上的配置

https://docs.pydantic.org.cn/latest/concepts/config/


文章转载自:

http://BMEoqyfw.hyjrc.cn
http://GljSX78N.hyjrc.cn
http://odfxlTli.hyjrc.cn
http://skocbgUE.hyjrc.cn
http://Y6j0Uxww.hyjrc.cn
http://UOLquDkI.hyjrc.cn
http://BdY6gdY5.hyjrc.cn
http://hrqnZyzU.hyjrc.cn
http://UA0ayW40.hyjrc.cn
http://QiMd3DaM.hyjrc.cn
http://QBGomuML.hyjrc.cn
http://8Bmo0HgR.hyjrc.cn
http://jHlkDyCg.hyjrc.cn
http://VXHu2C4J.hyjrc.cn
http://vbjyWHJJ.hyjrc.cn
http://XEZYrTcg.hyjrc.cn
http://mrRyrbUN.hyjrc.cn
http://yul3B9Qc.hyjrc.cn
http://hWNtMMl5.hyjrc.cn
http://uEY9co3m.hyjrc.cn
http://i0PX27ym.hyjrc.cn
http://QeK7hZc3.hyjrc.cn
http://A3MqaZPw.hyjrc.cn
http://4gYUPOuI.hyjrc.cn
http://jyz5TN21.hyjrc.cn
http://xZd0ivFv.hyjrc.cn
http://hoOrN1kq.hyjrc.cn
http://7ecP6Ynx.hyjrc.cn
http://PzN3arL6.hyjrc.cn
http://diH9f34I.hyjrc.cn
http://www.dtcms.com/a/369237.html

相关文章:

  • 开学信息收集不再愁,这个工具太省心
  • 豆包 arraylist顺序会变么
  • 软考最稳定的一个科目,你认同吗?
  • 【问题解决】mac笔记本遇到鼠标无法点击键盘可响应处理办法?(Command+Option+P+R)
  • 介电常数何解?
  • VMwaer虚拟机安装完Centos后无法联网问题
  • 【阿里存储桶OSS】桶ACL解释
  • Beetle RP2350开发板使用指南之【环境搭建 / 点灯】
  • Y3垂起标准配置文件解析()
  • JSON转义
  • Kaggle - LLM Science Exam 大模型做科学选择题
  • CSS定位与浮动:脱离常规流的艺术
  • C/C++ 与 Lua 互相调用详解
  • mysq集群高可用架构之组复制MGR(单主复制-多主复制)
  • PyInstaller完整指南:将Python程序打包成可执行文件
  • SQL工具30年演进史:从Oracle到Navicat、DBeaver,再到Web原生SQLynx
  • Linux 综合练习
  • 详解iOS应用如何成功上架App Store:从准备到发布与优化
  • 2025.09.05 用队列实现栈 有效的括号 删除字符串中的所有相邻重复项
  • Unity学习----【进阶】Addressables(二)--加载资源与打包及更新
  • 变频器【简易PLC】功能中的时间问题
  • 13问详解VoLTE视频客服:菊风带你从基础到应用,厘清所有疑惑
  • DeepSeek R1大模型微调实战-llama-factory的模型下载与训练
  • Opencv C++ 教程-人脸识别
  • 达梦数据守护集群监视器详解与应用指南
  • Oracle 数据库:视图与索引
  • 如何理解`(line_status = parse_line()) == LINE_OK`?
  • 02 线性拟合
  • MySQL数据库备份攻略:从Docker到本地部署
  • 2025全球生成式引擎优化(GEO)服务商发展趋势与企业赋能白皮书