olivebot/llm/agent/tools/DeleteTimer.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 sqlite3
from typing import Any
from langchain.tools import BaseTool
from llm.agent import agent_service
class DeleteTimer(BaseTool):
name: str = "DeleteTimer"
description: str = "用于删除某一个日程接受任务id作为参数2"
def __init__(self):
super().__init__()
def _run(self, para) -> str:
try:
id = int(para)
except ValueError:
return "输入的 ID 无效,必须是数字。"
try:
with sqlite3.connect('timer.db') as conn:
cursor = conn.cursor()
cursor.execute("DELETE FROM timer WHERE id = ?", (id,))
conn.commit()
except sqlite3.Error as e:
return f"数据库错误: {e}"
if id in agent_service.scheduled_tasks:
agent_service.scheduled_tasks[id].cancel()
del agent_service.scheduled_tasks[id]
return f"任务 {id} 取消成功。"
if __name__ == "__main__":
tool = DeleteTimer()
result = tool.run("1")
print(result)