money_tools.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. from langchain.tools import tool
  2. from .base_tool import call_csharp_api, get_tool_prompt
  3. def get_cusamt_default_config():
  4. """get_cusamt 工具的默认配置"""
  5. return {
  6. "get_cusamt": {
  7. "基础描述": "获取指定时间范围的收款数据,可指定客户、汇总方式,你根据时间跨度决定最佳的汇总方式",
  8. "入参说明": {
  9. "backend_url": "后端API地址",
  10. "token": "认证令牌",
  11. "cusname": "客户名称 或 客户编码, 支持模糊查询,留空即查询所有客户",
  12. "firstdate": "开始日期,格式YYYY-MM-DD",
  13. "lastdate": "结束日期,格式YYYY-MM-DD 23:59:59",
  14. "grouptype": "汇总方式,数值, 0:按天;1:按月;2:按年",
  15. },
  16. "返回值说明": {
  17. "格式": "一个包含客户收款数据的字符串",
  18. },
  19. "输出格式要求": ["以表格输出"],
  20. }
  21. }
  22. tool_description = get_tool_prompt("get_cusamt", get_cusamt_default_config())
  23. def get_cusamt_func(
  24. backend_url: str,
  25. token: str,
  26. cusname: str,
  27. firstdate: str,
  28. lastdate: str,
  29. grouptype: str,
  30. ) -> str:
  31. """实际的函数实现"""
  32. print(
  33. f"正在获取客户{cusname}在{firstdate}至{lastdate}的收款数据,汇总方式{grouptype}"
  34. )
  35. return call_csharp_api(
  36. backend_url,
  37. token,
  38. "money_data_ai",
  39. "get_cusamt",
  40. {
  41. "arg_cusname": cusname,
  42. "arg_firstdate": firstdate,
  43. "arg_lastdate": lastdate,
  44. "grouptype": grouptype,
  45. },
  46. )
  47. get_cusamt_func.__doc__ = tool_description
  48. get_cusamt = tool(get_cusamt_func)