React_tool.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. """企业业务工具"""
  2. from langchain_core.tools import tool
  3. # ================================
  4. # 工具1:查询订单系统
  5. # ================================
  6. @tool
  7. def query_order(order_id: str) -> str:
  8. """查询订单系统"""
  9. orders = {
  10. "10001": {
  11. "status": "运输中",
  12. "company": "顺丰",
  13. "days": 2,
  14. },
  15. "10002": {
  16. "status": "已退款",
  17. "company": "",
  18. "days": 0,
  19. },
  20. }
  21. return orders.get(
  22. order_id,
  23. "没有找到订单",
  24. )
  25. # ================================
  26. # 工具2:查询商品知识库
  27. # ================================
  28. @tool
  29. def query_product(product_name: str) -> str:
  30. """查询商品知识库"""
  31. products = {
  32. "无线耳机": {
  33. "category": "电子产品",
  34. "price": "299元",
  35. "warranty": "1年",
  36. },
  37. "机械键盘": {
  38. "category": "电脑外设",
  39. "price": "599元",
  40. "warranty": "2年",
  41. },
  42. }
  43. return products.get(
  44. product_name,
  45. "没有找到该商品信息",
  46. )
  47. tools = [
  48. query_order,
  49. query_product
  50. ]