大模型默认没有记忆

"""

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

"""

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_962078233 小时前
Python接口自动化流程(pytest)
python·pytest·接口自动化·测试框架·断言
杨女士YRJ3 小时前
python+pytest+01
python·pytest
鸽芷咕3 小时前
Mu Editor 鸿蒙 PC 适配全记录:用 Qt 与嵌入式 CPython 重建教学型 Python IDE
python·qt·harmonyos
微软技术分享3 小时前
基于 HuggingFace Tokenizers 训练自定义分词器
python·ubuntu·大模型·huggingface
gf13211113 小时前
python_调用远程服务器上的openclaw
服务器·python·php
lbb 小魔仙4 小时前
Jupyter Notebook / Lab 深度配置指南:插件 + 内核 + 远程访问 + 容器化部署
ide·python·jupyter
2601_962300474 小时前
python是跨平台的吗
python·开源·跨平台·面向对象·
2401_844582954 小时前
软件架构设计与持续重构:模块化开发实战建
python
东莞市云毅网络有限公司4 小时前
用 SQLite FTS5 给企业知识库做问答检索原型:中文二元切分与 BM25 排序
python·sqlite·自动化运维·geo·数据监测
承渊政道4 小时前
PR-Agent鸿蒙PC适配全记录:从Python服务端代理到ArkTS原生评审客户端
python·华为·代理模式·agent·harmonyos·pc端