| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- # @description:
- # @author: licanglong
- # @date: 2025/11/20 14:22
- import dirtyjson
- from app.prompt import industry_planner_prompt, source_researcher_prompt, industry_data_extractor_prompt
- from app.routes.base import base_router
- from app.service.llm_client import llm_call
- @base_router.post("/industry/data")
- async def get_industry_data():
- industry_input_data = ["011", "谷物种植", "1010101000000000000", "谷物"]
- tools = [
- {
- "type": "function",
- "function": {
- "name": "get_current_time",
- "description": "用于获取当前时间,当需求中涉及到了时间概念时可以使用",
- }
- }
- ,
- {
- "type": "function",
- "function": {
- "name": "ali_search_tool",
- "description": "当需要从互联网获取额外信息支撑时使用",
- "parameters": {
- "type": "object",
- "properties": {
- "keyword": {
- "type": "string",
- "description": "用于搜索的完整关键词,尽量将问题描述完整。如需限定来源,可在结尾使用“+ 来源机构名称”。"
- }
- },
- "required": ["keyword"]
- }
- }
- }
- ]
- industry_planner_messages = [
- {
- "role": "system",
- "content": industry_planner_prompt.system_prompt
- },
- {
- "role": "user",
- "content": industry_planner_prompt.user_prompt(industry_input_data)
- }
- ]
- industry_planner_data = await llm_call(tools=tools, messages=industry_planner_messages)
- source_researcher_messages = [
- {
- "role": "system",
- "content": source_researcher_prompt.system_prompt
- },
- {
- "role": "user",
- "content": source_researcher_prompt.user_prompt(industry_planner_data)
- }
- ]
- source_researcher_data = await llm_call(tools=tools, messages=source_researcher_messages)
- industry_data_extractor_messages = [
- {
- "role": "system",
- "content": industry_data_extractor_prompt.system_prompt
- },
- {
- "role": "user",
- "content": industry_data_extractor_prompt.user_prompt(
- [*industry_input_data, industry_planner_data, source_researcher_data])
- }
- ]
- industry_data_extractor = await llm_call(tools=tools, messages=industry_data_extractor_messages)
- return dirtyjson.loads(industry_data_extractor)
|