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