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

相关推荐
ZC跨境爬虫2 小时前
跟着MDN学HTML_day44:(ProcessingInstruction接口)
前端·javascript·ui·html·媒体
CODE202203182 小时前
promptfoo自定义prompt生成器
java·前端·prompt
222you2 小时前
Claude Code接入DeepSeek-v4模型
java·服务器·前端
原来是猿2 小时前
Linux守护进程(Daemon)完全指南:从原理到实战
linux·运维·服务器·网络·php
阡陌..2 小时前
如何使用samba为Linux设置一个局域网共享盘
linux·运维·服务器
轻口味2 小时前
AI 时代全栈开发破局:TypeScript 生态实战,从入门到部署一站式通关
前端·mongodb·docker·ai·typescript·react·next.js
ZC跨境爬虫2 小时前
跟着MDN学HTML_day_45:(EventTarget接口)
前端·javascript·ui·html·媒体
漂移的电子2 小时前
【el-tree】外层多选,某个属性内层单选
前端·javascript·vue.js