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

相关推荐
李剑一3 分钟前
面试第一关!面试官:讲一下事件循环机制,宏&微任务,还有渲染时机
前端·面试
shuoshuohaohao6 分钟前
《CSS》
前端·css
西部荒野子7 分钟前
Zustand 状态管理规范:别让轻量状态变成隐形通知风暴
前端·javascript
之歆7 分钟前
Day03_ES6 深度解析与实战应用:运算符、Symbol、Class、集合与迭代协议
前端·ecmascript·es6
Carson带你学Android17 分钟前
Kotlin放大招!官方 Skills 直接喂出「专家级」代码
android·前端·kotlin
之歆18 分钟前
Day04_ES6完全指南:从入门到精通的现代化JavaScript开发
前端·javascript·es6
Coffeeee22 分钟前
一个kotlin的Smart cast导致的编译问题
android·前端·kotlin
2401_8685347825 分钟前
防火墙的具体概念
服务器·网络·php
驭渊的小故事27 分钟前
网络初始1(2000字详细剖析网络的TCP/IP协议栈)
linux·服务器·网络