routes.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. # @description:
  2. # @author: licanglong
  3. # @date: 2025/11/20 14:22
  4. import dirtyjson
  5. from app.prompt import industry_planner_prompt, source_researcher_prompt, industry_data_extractor_prompt
  6. from app.routes.base import base_router
  7. from app.service.llm_client import llm_call
  8. @base_router.post("/industry/data")
  9. async def get_industry_data():
  10. industry_input_data = ["011", "谷物种植", "1010101000000000000", "谷物"]
  11. tools = [
  12. {
  13. "type": "function",
  14. "function": {
  15. "name": "get_current_time",
  16. "description": "用于获取当前时间,当需求中涉及到了时间概念时可以使用",
  17. }
  18. }
  19. ,
  20. {
  21. "type": "function",
  22. "function": {
  23. "name": "ali_search_tool",
  24. "description": "当需要从互联网获取额外信息支撑时使用",
  25. "parameters": {
  26. "type": "object",
  27. "properties": {
  28. "keyword": {
  29. "type": "string",
  30. "description": "用于搜索的完整关键词,尽量将问题描述完整。如需限定来源,可在结尾使用“+ 来源机构名称”。"
  31. }
  32. },
  33. "required": ["keyword"]
  34. }
  35. }
  36. }
  37. ]
  38. industry_planner_messages = [
  39. {
  40. "role": "system",
  41. "content": industry_planner_prompt.system_prompt
  42. },
  43. {
  44. "role": "user",
  45. "content": industry_planner_prompt.user_prompt(industry_input_data)
  46. }
  47. ]
  48. industry_planner_data = await llm_call(tools=tools, messages=industry_planner_messages)
  49. source_researcher_messages = [
  50. {
  51. "role": "system",
  52. "content": source_researcher_prompt.system_prompt
  53. },
  54. {
  55. "role": "user",
  56. "content": source_researcher_prompt.user_prompt(industry_planner_data)
  57. }
  58. ]
  59. source_researcher_data = await llm_call(tools=tools, messages=source_researcher_messages)
  60. industry_data_extractor_messages = [
  61. {
  62. "role": "system",
  63. "content": industry_data_extractor_prompt.system_prompt
  64. },
  65. {
  66. "role": "user",
  67. "content": industry_data_extractor_prompt.user_prompt(
  68. [*industry_input_data, industry_planner_data, source_researcher_data])
  69. }
  70. ]
  71. industry_data_extractor = await llm_call(tools=tools, messages=industry_data_extractor_messages)
  72. return dirtyjson.loads(industry_data_extractor)