olivebot/llm/agent/tools/QueryTimerDB.py
xszyou 87ed1c4425 Fay年翻更新
- 升级Agent(chat_module=agent切换):升级到langgraph react agent逻辑、集成到主分支fay中、基于自动决策工具调用机制、基于日程跟踪的主动沟通、支持外部观测数据传入;
- 修复因线程同步问题导致的配置文件读写不稳定
- 聊天采纳功能的bug修复
2024-11-20 23:44:47 +08:00

42 lines
1.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import abc
import sqlite3
from typing import Any
import ast
from langchain.tools import BaseTool
class QueryTimerDB(BaseTool, abc.ABC):
name: str = "QueryTimerDB"
description: str = "用于查询所有日程返回的数据里包含3个参数:时间、循环规则(如:'1000100'代表星期一和星期五循环,'0000000'代表不循环)、执行的事项"
def __init__(self):
super().__init__()
async def _arun(self, *args: Any, **kwargs: Any) -> Any:
# 用例中没有用到 arun 不予具体实现
pass
def _run(self, para) -> str:
conn = sqlite3.connect('timer.db')
cursor = conn.cursor()
# 执行查询
cursor.execute("SELECT * FROM timer")
# 获取所有记录
rows = cursor.fetchall()
# 拼接结果
result = ""
for row in rows:
result = result + str(row) + "\n"
conn.commit()
conn.close()
return result
if __name__ == "__main__":
tool = QueryTimerDB()
result = tool.run("")
print(result)