You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.1 KiB
40 lines
1.1 KiB
4 months ago
|
#!/usr/bin/env python
|
||
|
# -*- coding: utf-8 -*-
|
||
|
# @Time : 2025/4/19 18:27
|
||
|
# @Author : old-tom
|
||
|
# @File : local_test
|
||
|
# @Project : reActLLMDemo
|
||
|
# @Desc : 本地终端运行对话
|
||
|
import langgraph.store.memory
|
||
|
from llmagent.assistant_graph import graph
|
||
|
|
||
|
|
||
|
def stream_graph_updates(user_input: str):
|
||
|
"""
|
||
|
流式输出
|
||
|
:param user_input:
|
||
|
:return:
|
||
|
"""
|
||
|
config = {"configurable": {"thread_id": "1"}}
|
||
|
for chunk, metadata in graph.stream({"messages": [{"role": "user", "content": user_input}]}, config,
|
||
|
stream_mode='messages'):
|
||
|
if chunk.content:
|
||
|
print(chunk.content, end='', flush=True)
|
||
|
print('\n')
|
||
|
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
while True:
|
||
|
try:
|
||
|
user_input = input("User: ")
|
||
|
if user_input.lower() in ["quit", "exit", "q"]:
|
||
|
print("Goodbye!")
|
||
|
break
|
||
|
|
||
|
stream_graph_updates(user_input)
|
||
|
except:
|
||
|
user_input = "What do you know about LangGraph?"
|
||
|
print("User: " + user_input)
|
||
|
stream_graph_updates(user_input)
|
||
|
break
|