cust_data_tools.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. from langchain.tools import tool
  2. from .base_tool import call_csharp_api, get_tool_prompt
  3. from typing import Optional
  4. def get_cust_info_default_config():
  5. """get_cust_info 工具的默认配置"""
  6. return {
  7. "get_cust_info": {
  8. "基础描述": "获取指定客户的详细信息",
  9. "入参说明": {
  10. "backend_url": "后端API地址",
  11. "token": "认证令牌",
  12. "cusname": "客户名称",
  13. },
  14. "返回值说明": {"格式": "一个包含客户信息的字符串"},
  15. "输出格式要求": [
  16. "**客户:**{cusname}",
  17. "**性质:**{state}",
  18. "**地区:**{areaname}",
  19. "**业务员:**{custype}",
  20. "**联系人:**{rep}",
  21. "**联系方式:**{contact}",
  22. "**地址:**{address}",
  23. "**常购型号**",
  24. "| 型号 | 产品名称 | 单位 | 近6个月采购量 | 上月采购量 |",
  25. "| :--- | :--- | :--- | :--- | :--- |",
  26. "| mtrlcode | mtrlname | unit | saleqty_halfyear | saleqty_lastmonth |",
  27. ],
  28. "使用示例": "查一下客户 南华家具",
  29. }
  30. }
  31. tool_description = get_tool_prompt("get_cust_info", get_cust_info_default_config())
  32. def get_cust_info_func(
  33. backend_url: str,
  34. token: str,
  35. cusname: str = "",
  36. ) -> str:
  37. """实际的函数实现"""
  38. print(f"正在获取客户信息{cusname}")
  39. return call_csharp_api(
  40. backend_url,
  41. token,
  42. "cust_data_ai",
  43. "get_cust_info",
  44. {"arg_cusname": cusname},
  45. )
  46. get_cust_info_func.__doc__ = tool_description
  47. get_cust_info = tool(get_cust_info_func)