Commit 031dfa1e by tinywell

1设备传感器数量查询接口接入;问题类型识别参数说明优化;工具返回数据结构精简

parent a086b59c
......@@ -161,7 +161,7 @@ class MonitorClient(BaseHttpClient):
"deviceType": device_type
}
)
return BaseResponse[List](**data)
return BaseResponse[Dict](**data)
# 示例:添加新的数据接口客户端
class RateClient(BaseHttpClient):
......
......@@ -124,11 +124,25 @@ class RegionRateTool(BaseRateTool):
for item in df.resultdata:
rate_date = self._extract_rate_data(item)
result_data.append(rate_date)
sorted_data = [rate_date[0]]
if len(result_data) > 1:
sorted_data.extend(sorted(result_data[1:], key=lambda x: x['在线率']))
# 将数据改成表格形式,表头提取之后,数据一行行显示
table_header = list(result_data[0].keys())
table_data = []
for item in result_data:
table_data.append(list(item.values()))
result_data = {
'table_header': table_header,
'table_data': table_data
}
data = {
'region': region_name,
'region_code': code,
'rate_data': result_data,
'region': region_name,
'region_code': code,
'rate_data': result_data,
}
total_time = time.time() - agent_start
......@@ -160,6 +174,16 @@ class RegionRateTool(BaseRateTool):
self.logger.debug(f"查询结果: {df.resultdata}")
# markdown = self.to_markdown(df.resultdata)
table_header = list(result_data[0].keys())
table_data = []
for item in result_data:
table_data.append(list(item.values()))
result_data = {
'table_header': table_header,
'table_data': table_data
}
data = {
'region': region_name,
......
......@@ -26,7 +26,7 @@ DEFAULT_CONFIG = {
"API_BASE": "http://192.168.10.14:8000/v1",
"TOOL_BASE_URL": "http://localhost:5001",
"API_KEY": "xxxxxxxxxxxxx",
"LOG_LEVEL": "DEBUG"
"LOG_LEVEL": "INFO"
}
def get_config(key: str, args: Optional[argparse.Namespace] = None) -> str:
......
......@@ -80,10 +80,20 @@ def run_examples():
"expected": {
"tool": "monitor_points_query",
"params": {
"key": "甘肃省陇南市"
"key": "甘肃省"
}
}
},
},{
"query": "贵阳市的雨量传感器有多少",
"expected": {
"tool": "monitor_points_query",
"params": {
"key": "贵阳市",
"device_type": "雨量",
"query_type": "2",
}
}
}
]
# 为每个测试案例创建一个表格
......@@ -120,10 +130,10 @@ def run_examples():
"✓" if expected_value == actual_value else "✗"
)
# run tool
tool = tools_dict[actual_tool]
result = tool.invoke(result["params"])
print(result)
# # run tool
# tool = tools_dict[actual_tool]
# result = tool.invoke(result["params"])
# print(result)
except Exception as e:
table.add_row("错误", "", str(e), "✗")
......
......@@ -44,6 +44,7 @@ def run_examples():
"start_time": "2024-04-01 00:00:00",
"end_time": "2024-05-31 23:59:59",
"region_name": "甘肃省",
"query_type": "1",
}
}
},{
......@@ -64,6 +65,7 @@ def run_examples():
"start_time": "2024-01-01 00:00:00",
"end_time": "2024-12-31 23:59:59",
"region_name": "甘肃省",
"query_type": "2",
}
}
},{
......@@ -74,6 +76,7 @@ def run_examples():
"start_time": "2024-01-01 00:00:00",
"end_time": "2024-06-30 23:59:59",
"region_name": "甘肃省",
"query_type": "1",
}
}
}
......@@ -113,11 +116,11 @@ def run_examples():
"✓" if expected_value == actual_value else "✗"
)
tool = tool_dict[result["tool"]]
params = result["params"]
# tool = tool_dict[result["tool"]]
# params = result["params"]
result = tool.invoke(params)
print(result)
# result = tool.invoke(params)
# print(result)
except Exception as e:
table.add_row("错误", "", str(e), "✗")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment