feat: tools agent refactor for custom fields and unique actions

This commit is contained in:
Siddhant Rai
2024-12-19 20:34:20 +05:30
parent f67b79f007
commit 4c3f990d4b
3 changed files with 104 additions and 81 deletions

View File

@@ -12,7 +12,6 @@ class TelegramTool(Tool):
def __init__(self, config):
self.config = config
self.token = config.get("token", "")
self.chat_id = config.get("chat_id", "")
def execute_action(self, action_name, **kwargs):
actions = {
@@ -25,17 +24,17 @@ class TelegramTool(Tool):
else:
raise ValueError(f"Unknown action: {action_name}")
def _send_message(self, text):
def _send_message(self, text, chat_id):
print(f"Sending message: {text}")
url = f"https://api.telegram.org/bot{self.token}/sendMessage"
payload = {"chat_id": self.chat_id, "text": text}
payload = {"chat_id": chat_id, "text": text}
response = requests.post(url, data=payload)
return {"status_code": response.status_code, "message": "Message sent"}
def _send_image(self, image_url):
def _send_image(self, image_url, chat_id):
print(f"Sending image: {image_url}")
url = f"https://api.telegram.org/bot{self.token}/sendPhoto"
payload = {"chat_id": self.chat_id, "photo": image_url}
payload = {"chat_id": chat_id, "photo": image_url}
response = requests.post(url, data=payload)
return {"status_code": response.status_code, "message": "Image sent"}
@@ -43,14 +42,18 @@ class TelegramTool(Tool):
return [
{
"name": "telegram_send_message",
"description": "Send a notification to telegram chat",
"description": "Send a notification to Telegram chat",
"parameters": {
"type": "object",
"properties": {
"text": {
"type": "string",
"description": "Text to send in the notification",
}
},
"chat_id": {
"type": "string",
"description": "Chat ID to send the notification to",
},
},
"required": ["text"],
"additionalProperties": False,
@@ -65,7 +68,11 @@ class TelegramTool(Tool):
"image_url": {
"type": "string",
"description": "URL of the image to send",
}
},
"chat_id": {
"type": "string",
"description": "Chat ID to send the image to",
},
},
"required": ["image_url"],
"additionalProperties": False,
@@ -75,9 +82,5 @@ class TelegramTool(Tool):
def get_config_requirements(self):
return {
"chat_id": {
"type": "string",
"description": "Telegram chat ID to send messages to",
},
"token": {"type": "string", "description": "Bot token for authentication"},
}