From 759fa85dd1ce7eac2822f366815c799328a420d5 Mon Sep 17 00:00:00 2001 From: goulustis Date: Wed, 22 Oct 2025 14:14:51 +0800 Subject: [PATCH] move chat to demo chat --- lang_agent/pipeline.py | 35 ++++------------------------------- scripts/demo_chat.py | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+), 31 deletions(-) create mode 100644 scripts/demo_chat.py diff --git a/lang_agent/pipeline.py b/lang_agent/pipeline.py index 33e2d90..533b6a2 100644 --- a/lang_agent/pipeline.py +++ b/lang_agent/pipeline.py @@ -14,6 +14,7 @@ from langchain.agents import create_agent from langgraph.checkpoint.memory import MemorySaver from lang_agent.config import InstantiateConfig, KeyConfig +from lang_agent.graphs import AnnotatedGraph from lang_agent.graphs.react import ReactGraph, ReactGraphConfig @@ -41,7 +42,8 @@ class PipelineConfig(KeyConfig): port:int = 23 """what is my port""" - graph_config: ReactGraphConfig = field(default_factory=ReactGraphConfig) + # graph_config: ReactGraphConfig = field(default_factory=ReactGraphConfig) + graph_config: AnnotatedGraph = field(default_factory=ReactGraphConfig) @@ -126,33 +128,4 @@ class Pipeline: out = self.invoke(*inp, as_stream=as_stream) - return out['messages'][-1].content - - -import signal -import sys -def signal_handler(sig, frame): - """Handle Ctrl+C signal for graceful shutdown""" - print("\n程序正在退出...") - sys.exit(0) - -def main(): - # Register signal handler for Ctrl+C - signal.signal(signal.SIGINT, signal_handler) - - pipeline_config = PipelineConfig() - pipeline: Pipeline = pipeline_config.setup() - - # 进行循环对话 - while True: - - user_input = input("请讲:") - if user_input.lower() == "exit": - break - response = pipeline.chat(user_input, as_stream=True) - print(f"回答: {response}") - - -if __name__ == "__main__": - # asyncio.run(main()) - main() \ No newline at end of file + return out['messages'][-1].content \ No newline at end of file diff --git a/scripts/demo_chat.py b/scripts/demo_chat.py new file mode 100644 index 0000000..cf16f53 --- /dev/null +++ b/scripts/demo_chat.py @@ -0,0 +1,23 @@ +import tyro +import asyncio + +from lang_agent.pipeline import Pipeline, PipelineConfig +from lang_agent.config import load_tyro_conf + +def main(conf:PipelineConfig): + if conf.config_f is not None: + conf = load_tyro_conf(conf.config_f) + + pipeline:Pipeline = conf.setup() + + while True: + + user_input = input("请讲:") + if user_input.lower() == "exit": + break + response = pipeline.chat(user_input, as_stream=True) + print(f"回答: {response}") + + +if __name__ == "__main__": + main(tyro.cli(PipelineConfig)) \ No newline at end of file