olivebot/agent/tools/GetSwitchLog.py
xszyou 01c19c13e8 工作愉快
*实现agent ReAct与LLM chain自动切换逻辑✓

聊天窗区分任务消息✓

修复删除日程bug✓

优化远程音频逻辑✓

等待处理引入加载中效果✓

优化prompt以解决日程任务递归调用问题✓

修复一次性日程清除的bug✓
2023-12-25 22:13:09 +08:00

49 lines
1.2 KiB
Python

import os
from typing import Any
from langchain.tools import BaseTool
import tools.IotmService as IotmService
class GetSwitchLog(BaseTool):
name = "GetSwitchLog"
description = "此工具用于查询农业箱的设备开关当天的操作历史记录"
def __init__(self):
super().__init__()
async def _arun(self, *args: Any, **kwargs: Any) -> Any:
# 用例中没有用到 arun 不予具体实现
pass
def _run(self, para: str):
logs = IotmService.get_switch_log()
device_logs = {}
switch_mapping = {
1: '小风扇',
2: '电热风扇',
3: '制冷风扇',
4: '水开关',
5: '肥料开关',
6: '植物生长灯',
7: '二氧化碳'
}
for val in logs:
switch_name = switch_mapping[val['number']]
status = 'on' if val['status'] == 1 else 'off'
info = val['timetText']
if switch_name not in device_logs:
device_logs[switch_name] = {'on': [], 'off': []}
device_logs[switch_name][status].append(info)
return device_logs
if __name__ == "__main__":
tool = GetSwitchLog()
info = tool.run("")
print(info)