cli.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. from __future__ import annotations
  2. import argparse
  3. import sys
  4. from app.config import get_settings
  5. from app.schemas import QueryRequest
  6. from app.service import AgenticRAGService
  7. def main() -> None:
  8. # Windows 控制台可能使用 GBK;网页证据中的 € 等字符不能直接编码。
  9. # 保留当前控制台编码,只将不支持的字符转义,避免输出阶段中断业务流程。
  10. if hasattr(sys.stdout, "reconfigure"):
  11. sys.stdout.reconfigure(errors="backslashreplace")
  12. parser = argparse.ArgumentParser(description="Agentic RAG 命令行入口")
  13. parser.add_argument("query", help="用户问题")
  14. parser.add_argument("--debug", action="store_true", help="输出完整执行轨迹")
  15. args = parser.parse_args()
  16. response = AgenticRAGService(get_settings()).invoke(
  17. QueryRequest(query=args.query, debug=args.debug)
  18. )
  19. if args.debug:
  20. print("=== 实际执行的工具查询 ===")
  21. for item in response.executed_queries:
  22. print(
  23. f"- {item['tool']}: query={item['query']!r}, "
  24. f"arguments={item['arguments']}, status={item['status']}"
  25. )
  26. print("=== 完整响应 ===")
  27. print(response.model_dump_json(indent=2))
  28. if __name__ == "__main__":
  29. main()