大模型默认没有记忆

"""

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

"""

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

相关推荐
EW Frontier6 分钟前
【DOA估计】四根天线、一块SDR,神经网络把测向误差压进2度以内【附python代码】
人工智能·python·神经网络·doa估计·aoa估计
denggun123458 分钟前
Python两套原生信号量与swift对比
开发语言·python·swift
qq_161111272 小时前
Jenkins+Python自动化测试持续集成详细教程
自动化测试·python·jenkins·教程·持续集成
爱吃苹果的梨叔5 小时前
训练集群网络中断怎么办?智算机房的 Console 串口排障方案
网络·python·智能路由器·php
李妍.9 小时前
02Numpy基础(上)
开发语言·python
TheBestRucy9 小时前
Python 九阳神功之贰:面向对象(下)
开发语言·python
2601_965958469 小时前
口腔黏膜脱皮超2周未愈建议及时就医
人工智能·python
微小冷10 小时前
在不同空间中展示数据(欧式、球面、庞加莱圆盘)
python·双曲空间·微分几何·geomstats·庞加莱圆盘·球面
weixin_4316004410 小时前
Agent Workflow 学习向:Code 节点,比模板更强的变量加工
后端·python·学习·ai·
讲温控就好了11 小时前
从医疗影像到能源存储——芯片冷却温控技术的跨行业赋能
人工智能·python·能源