大模型默认没有记忆

"""

创建一个静态模型的智能体

"""

import json

from langchain.agents import create_agent

from langchain.chat_models import init_chat_model

from langchain.tools import tool

from langgraph.graph.state import CompiledStateGraph

from env_utils import DEEPSEEK_API_KEY, DEEPSEEK_BASE_URL

from langchain_core.messages import AnyMessage

"""

基本控制: 串行控制

基本控制: 分支控制

Successfully installed langchain-core-1.4.0

langchain-protocol-0.0.15 langgraph-1.2.0

langgraph-checkpoint-4.1.0 langgraph-prebuilt-1.1.0 ormsgpack-1.12.2

"""

from langchain_core.messages import AnyMessage

from typing_extensions import TypedDict

from langgraph.graph import START,StateGraph,END

from IPython.display import Image,display

from typing import Any, Annotated, Literal

import operator

from langgraph.graph import StateGraph,MessagesState,START

import os

from langgraph.graph import StateGraph,MessagesState,START

from langchain_deepseek import ChatDeepSeek

model = ChatDeepSeek(

model="deepseek-v4-pro",

api_key=os.environ.get("DEEPSEEK_API_KEY"),

base_url=os.environ.get("DEEPSEEK_BASE_URL")

)

def call_model(state: MessagesState) :

response=model.invoke(state"messages")

return {"messages":response}

builder = StateGraph(MessagesState)

builder.add_node("call_model",call_model)

builder.add_edge(START,"call_model")

graph=builder.compile()

input_message = {"role":"user","content":"hi,我是tomie"}

for chunk in graph.stream({"messages":input_message},stream_mode= "values"):

chunk"messages"-1.pretty_print()

input_message = {"role": "user", "content": "我叫什么名字"}

for chunk in graph.stream({"messages": input_message}, stream_mode="values"):

chunk"messages"-1.pretty_print()

D:\Users\msi\miniconda3\python.exe D:\nanobot-main\langchain-demo\my_llm22.py

================================ Human Message =================================

hi,我是tomie

================================== Ai Message ==================================

Hi Tomie!很高兴认识你!😊

我是 DeepSeek,一个由深度求索公司创造的 AI 助手。我可以陪你聊天、回答问题、帮你处理文件、提供建议,或者聊聊任何你感兴趣的话题。

今天有什么想聊的,或者需要我帮忙的吗?

================================ Human Message =================================

我叫什么名字

================================== Ai Message ==================================

我目前不知道你的名字哦。我们才刚开始聊天,你还没有告诉我呢!

如果你愿意的话,可以告诉我你的名字,或者说说你想让我怎么称呼你~ 😊

Process finished with exit code 0

相关推荐
2601_9679791223 分钟前
pip在Python中的9个必须知道的用法
python·pip·版本控制·包管理工具·requirements.txt
曲径海盗41 分钟前
【Python 学习第 58 天】列表方法
python·学习笔记·编程入门
DeepVisionary44 分钟前
Runway开源机器人大模型Praxis-1,推演延迟压到62毫秒
python·自动化
Cooper252 小时前
DDC 命令成功但屏幕不动:用 gamma 表重做亮度映射
python·mac
师夷长技以自愈3 小时前
手搓 AI Agent 第 7 篇:菜做砸了别硬炒——错误分类 + 双账本熔断
人工智能·python
用户956256254293 小时前
15 分钟社媒简报 Agent:我只用了搜索和模型两步
python·api
Dumbness3 小时前
关键词回复里写了 {订单号},群机器人整条消息都炸了
python·微信
调接口的阿光3 小时前
调用对话接口时输出被截断怎么办:先看 finish_reason,再决定是续写一次、缩小范围,还是换成更短的格式(Python)
人工智能·python
Cooper253 小时前
单文件 Flask 跑通微信服务器校验:先跑通再谈工程化
python·flask
Cooper253 小时前
三源热榜去重加 AI 摘要:URL 唯一键踩出的三个坑
前端·python