大模型默认没有记忆

"""

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

"""

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

相关推荐
MepSUxjvy10 小时前
002:RAG 入门-LangChain 读取文本
开发语言·python·langchain
晚烛10 小时前
CANN 数据增强 on NPU:训练数据增强的 NPU 加速实战
人工智能·python·深度学习·缓存·数据挖掘
AI算法沐枫10 小时前
机器学习知识点:正则化
人工智能·pytorch·python·深度学习·神经网络·算法·机器学习
专注VB编程开发20年11 小时前
python语法设计、IDE 生态、平台策略、解析器逻辑这四层的矛盾点
开发语言·ide·python
爱睡懒觉的焦糖玛奇朵18 小时前
【从视频到数据集:焦糖玛奇朵的魔法工具使用说明】
人工智能·python·深度学习·学习·算法·yolo·音视频
yangshicong19 小时前
第11章:结构化输出与数据提取 —— 让 AI 直接返回你想要的数据格式
数据库·人工智能·redis·python·langchain·ai编程
言之。20 小时前
【Python】免费的中文 AI 配音方案
开发语言·人工智能·python
Warson_L20 小时前
python dict key详解
python
天天进步201520 小时前
Python全栈项目:从零手操一个高性能 API 网关
开发语言·python