sale_tools.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. from langchain.tools import tool
  2. from .base_tool import call_csharp_api, get_tool_prompt
  3. def get_sale_amt_default_config():
  4. """get_sale_amt 工具的默认配置"""
  5. return {
  6. "get_sale_amt": {
  7. "基础描述": "获取指定时间范围的销售金额,按月汇总",
  8. "入参说明": {
  9. "backend_url": "后端API地址",
  10. "token": "认证令牌",
  11. "funtion_name": "函数名称; get_sale_amt_by_month:按月汇总销售额; get_sale_amt_by_day:按天汇总销售额; get_sale_amt_by_produce:产品销售额; get_sale_amt_by_cus:客户销售额",
  12. "firstdate": "开始日期,格式YYYY-MM-DD",
  13. "lastdate": "结束日期,格式YYYY-MM-DD 23:59:59",
  14. },
  15. "返回值说明": {
  16. "格式": "一个包含销售金额的字符串",
  17. },
  18. "输出格式要求": [
  19. "以自然语言描述形式输出,不要使用表格",
  20. "重复信息要总结归纳,精简显示",
  21. ],
  22. }
  23. }
  24. tool_description = get_tool_prompt("get_sale_amt", get_sale_amt_default_config())
  25. def get_sale_amt_func(
  26. backend_url: str, token: str, funtion_name: str, firstdate: str, lastdate: str
  27. ) -> str:
  28. """实际的函数实现"""
  29. print(f"正在获取销售金额{funtion_name},时间范围:{firstdate} 至 {lastdate}")
  30. return call_csharp_api(
  31. backend_url,
  32. token,
  33. "sale_data_ai",
  34. funtion_name,
  35. {"arg_firstdate": firstdate, "arg_lastdate": lastdate},
  36. )
  37. get_sale_amt_func.__doc__ = tool_description
  38. get_sale_amt = tool(get_sale_amt_func)