test_resource_graph.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. from __future__ import annotations
  2. """测试资源查询阶段子图:验证航班和酒店搜索的完整流程(调用真实MCP服务)。"""
  3. import asyncio
  4. from rich.console import Console
  5. from app.graph.travel_builder import (
  6. build_resource_graph,
  7. )
  8. console = Console()
  9. async def main() -> None:
  10. graph = await build_resource_graph()
  11. result = await graph.ainvoke(
  12. {
  13. "user_query": (
  14. "我和妻子计划2026年8月10日"
  15. "从上海去成都,8月13日返回,"
  16. "总预算8000元。"
  17. "喜欢熊猫、自然景观和川菜,"
  18. "不想安排太赶。"
  19. "酒店希望靠近地铁,"
  20. "每晚不超过600元。"
  21. "机票不限制是否中转。"
  22. ),
  23. "errors": [],
  24. "missing_fields": [],
  25. }
  26. )
  27. console.rule("[bold]最终状态摘要")
  28. console.print(result["final_answer"])
  29. console.print(
  30. {
  31. "出发机场": result.get(
  32. "origin_airports"
  33. ),
  34. "目的机场": result.get(
  35. "destination_airports"
  36. ),
  37. "航班候选数": (
  38. result.get(
  39. "flight_search_result",
  40. {},
  41. ).get("total_count")
  42. ),
  43. "酒店候选数": (
  44. result.get(
  45. "hotel_search_result",
  46. {},
  47. ).get("total_count")
  48. ),
  49. "错误": result.get("errors"),
  50. }
  51. )
  52. if __name__ == "__main__":
  53. asyncio.run(main())