pydantic格式输出

from langchain.agents import create_agent

from langchain_deepseek import ChatDeepSeek

from pydantic import BaseModel,Field

from env_utils import DEEPSEEK_API_KEY,DEEPSEEK_BASE_URL

from langchain.agents import create_agent,AgentState

from langchain_core.tools import tool

from langgraph.checkpoint.memory import InMemorySaver

from langgraph.prebuilt import ToolRuntime

deepseek_llm = ChatDeepSeek(model='deepseek-chat',

api_key=DEEPSEEK_API_KEY,

base_url=DEEPSEEK_BASE_URL)

class Movie(BaseModel):

title: str = Field(description="电影的标题")

director: str = Field(description="电影的导演")

year: int = Field(description="电影的上映年份")

rating: float = Field(description="电影的评分")

model_with_structured_output= deepseek_llm.with_structured_output(Movie)

res=model_with_structured_output.invoke("介绍下电影《速度与激情》?")

print(res)

title='速度与激情' director='罗伯·科恩' year=2001 rating=6.8

相关推荐
布莱克6051 天前
Swift 类详解:从定义、继承到内存管理的完整指南
服务器·开发语言·ios·ssh·swift·类
布莱克6051 天前
Swift 方法详解:实例方法、类型方法与 mutating 机制
服务器·开发语言·ios·ssh·swift·方法
Rabitebla1 天前
【Linux】文件篇(五):手撕简易 FILE——模拟实现 C 标准 I/O 缓冲机制
linux·服务器·c语言·笔记·学习·ubuntu
FRing031 天前
vue3干货总结3(defineOptions(Vue3.3)、defineModel(Vue3.4)、Pinia)
开发语言·前端·vue.js·vue3
Bczheng11 天前
组件化服务端渲染模式SSR
前端
whitelbwwww1 天前
CUDA C++实战--中级
开发语言·前端·c++
张紫娃1 天前
Chrome插件-Stylus(屏蔽博客广告)
前端·chrome·stylus
Yannik1 天前
在 Apple Silicon Mac 上用 Jenkins + Fastlane 搭建 iOS CI:从自动打包到 MR 检查流水线的完整实践
前端
Nayana1 天前
《Web 到 HarmonyOS》-- 打包:Vite 产物 → HAP / HAR / HSP
前端
inksci1 天前
用飞帆做了个小网页
前端·javascript·css·html