大模型默认没有记忆

"""

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

"""

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

相关推荐
happylifetree2 小时前
Python70:核心语法-函数进阶-案例2
python
王中阳Go3 小时前
两个入口答案不一致先别调模型:6 行入口口径对账表(附脚本)
人工智能·后端·python·大语言模型·1024程序员节
BK贝壳3 小时前
bool-hybrid-array 落盘我只认 .bha:用 Create_BHA / Ask_BHA 做布尔数组序列化
数据结构·python·numpy·1024程序员节
Sakura_j_h_4 小时前
Python 在定时任务里输出 emoji,UnicodeEncodeError 从哪来
开发语言·字符编码·windows·python·定时任务
supabc1235 小时前
欧盟电子发票(XRechnung/Peppol/ZUGFeRD)踩坑记:用 Python 不装 Java 跑官方校验规则
xml·python·开源·电子发票·1024程序员节
ZhengEnCi5 小时前
AI Agent工具调用防护层怎么写-一份能直接跑的Python四层拦截实现
python·llm·agent
ZhengEnCi6 小时前
AI Agent工具误调用怎么解决-从参数校验到高危二次确认的四层工程防线
python·llm·agent
镜子AI7 小时前
镜子AI工程教程:用Python实现关键词布局检查器与语义改写查重(附完整代码)
人工智能·python·microsoft
小oo呆8 小时前
【学习心得】Python协程
python
信誓旦旦的程序猿8 小时前
【Python量化实战宝典 #22】涨跌停、连板情绪手册:情绪指标构建(Python 可跑)
python·1024程序员节·股票数据api·股票数据api接口·股票api数据接口·股票量化数据api·股票量化数据接口