From a283f7dde923daeaab8dd29c624b487170cb9582 Mon Sep 17 00:00:00 2001 From: Jonathan Lucas Date: Sun, 18 Aug 2024 09:19:29 -0500 Subject: [PATCH] Removed image, added clear implementation to github_tool and log_tool --- telegram_inference_bot.py | 29 +++-------------------------- tools/github_tool.py | 5 +++++ tools/log_tool.py | 3 +++ 3 files changed, 11 insertions(+), 26 deletions(-) diff --git a/telegram_inference_bot.py b/telegram_inference_bot.py index e12e192..faae2de 100644 --- a/telegram_inference_bot.py +++ b/telegram_inference_bot.py @@ -2,8 +2,6 @@ import json import os import importlib import inspect -import tempfile -import base64 import logging import anthropic from telegram import Update @@ -48,9 +46,6 @@ with open("prompts/developer_prompt.txt", "r") as file: # Dictionary to store conversation history for each user conversation_history = {} -# Dictionary to store the last image file for each user -user_images = {} - # Load tools tools = [] tools_dir = os.path.join(os.path.dirname(__file__), 'tools') @@ -75,29 +70,12 @@ async def clear(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: user_id = update.effective_user.id if user_id in conversation_history: del conversation_history[user_id] - if user_id in user_images: - os.remove(user_images[user_id]) - del user_images[user_id] + for tool in tools: + tool.clear() + logging.info(f"Cleared conversation history and image for user {user_id}") await update.message.reply_text("Conversation history and image cleared. Let's start fresh!") -async def handle_image(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: - user_id = update.effective_user.id - - # Get the largest available photo - photo = max(update.message.photo, key=lambda x: x.file_size) - - # Download the photo - photo_file = await context.bot.get_file(photo.file_id) - - # Create a temporary file to store the image - with tempfile.NamedTemporaryFile(delete=False, suffix='.jpg') as temp_file: - await photo_file.download_to_drive(custom_path=temp_file.name) - user_images[user_id] = temp_file.name - - logging.info(f"Received image from user {user_id}") - await update.message.reply_text("I've received your image. What would you like to know about it?") - async def handle_message(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: try: user_id = update.effective_user.id @@ -224,7 +202,6 @@ def main() -> None: application.add_handler(CommandHandler("switch", switch)) application.add_handler(CommandHandler("toggle", switch_anthropic)) application.add_handler(CommandHandler("status", status)) - application.add_handler(MessageHandler(filters.PHOTO, handle_image)) application.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, handle_message)) # Start the Bot diff --git a/tools/github_tool.py b/tools/github_tool.py index 4e1a472..9dc8696 100644 --- a/tools/github_tool.py +++ b/tools/github_tool.py @@ -37,6 +37,11 @@ class GitHubTool(BaseTool): self.logger.addHandler(file_handler) self.logger.addHandler(console_handler) + def clear(self): + if (self.current_branch != "main"): + self._set_current_branch("main") + pass + def get_functions(self): return [ { diff --git a/tools/log_tool.py b/tools/log_tool.py index 18bd33c..f4dc203 100644 --- a/tools/log_tool.py +++ b/tools/log_tool.py @@ -28,6 +28,9 @@ class LogTool(BaseTool): self.logger.addHandler(file_handler) self.logger.addHandler(console_handler) + def clear(self): + pass + def get_functions(self): return [ {