cli.py 639 B

1234567891011121314151617181920212223
  1. from .chain import create_chat_agent
  2. from .config import load_config
  3. def run_chat() -> None:
  4. config = load_config()
  5. agent = create_chat_agent(config)
  6. run_config = {"configurable": {"thread_id": config.default_session_id}}
  7. while True:
  8. question = input("请输入: ").strip()
  9. if not question:
  10. continue
  11. if question.lower() in ["exit", "quit", "q"]:
  12. break
  13. result = agent.invoke(
  14. {"messages": [{"role": "user", "content": question}]},
  15. config=run_config,
  16. )
  17. answer = result["messages"][-1].content
  18. print(f"AI: {answer}")