Removed image, added clear implementation to github_tool and log_tool
This commit is contained in:
@@ -2,8 +2,6 @@ import json
|
|||||||
import os
|
import os
|
||||||
import importlib
|
import importlib
|
||||||
import inspect
|
import inspect
|
||||||
import tempfile
|
|
||||||
import base64
|
|
||||||
import logging
|
import logging
|
||||||
import anthropic
|
import anthropic
|
||||||
from telegram import Update
|
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
|
# Dictionary to store conversation history for each user
|
||||||
conversation_history = {}
|
conversation_history = {}
|
||||||
|
|
||||||
# Dictionary to store the last image file for each user
|
|
||||||
user_images = {}
|
|
||||||
|
|
||||||
# Load tools
|
# Load tools
|
||||||
tools = []
|
tools = []
|
||||||
tools_dir = os.path.join(os.path.dirname(__file__), '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
|
user_id = update.effective_user.id
|
||||||
if user_id in conversation_history:
|
if user_id in conversation_history:
|
||||||
del conversation_history[user_id]
|
del conversation_history[user_id]
|
||||||
if user_id in user_images:
|
for tool in tools:
|
||||||
os.remove(user_images[user_id])
|
tool.clear()
|
||||||
del user_images[user_id]
|
|
||||||
logging.info(f"Cleared conversation history and image for user {user_id}")
|
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!")
|
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:
|
async def handle_message(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
||||||
try:
|
try:
|
||||||
user_id = update.effective_user.id
|
user_id = update.effective_user.id
|
||||||
@@ -224,7 +202,6 @@ def main() -> None:
|
|||||||
application.add_handler(CommandHandler("switch", switch))
|
application.add_handler(CommandHandler("switch", switch))
|
||||||
application.add_handler(CommandHandler("toggle", switch_anthropic))
|
application.add_handler(CommandHandler("toggle", switch_anthropic))
|
||||||
application.add_handler(CommandHandler("status", status))
|
application.add_handler(CommandHandler("status", status))
|
||||||
application.add_handler(MessageHandler(filters.PHOTO, handle_image))
|
|
||||||
application.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, handle_message))
|
application.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, handle_message))
|
||||||
|
|
||||||
# Start the Bot
|
# Start the Bot
|
||||||
|
|||||||
@@ -37,6 +37,11 @@ class GitHubTool(BaseTool):
|
|||||||
self.logger.addHandler(file_handler)
|
self.logger.addHandler(file_handler)
|
||||||
self.logger.addHandler(console_handler)
|
self.logger.addHandler(console_handler)
|
||||||
|
|
||||||
|
def clear(self):
|
||||||
|
if (self.current_branch != "main"):
|
||||||
|
self._set_current_branch("main")
|
||||||
|
pass
|
||||||
|
|
||||||
def get_functions(self):
|
def get_functions(self):
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -28,6 +28,9 @@ class LogTool(BaseTool):
|
|||||||
self.logger.addHandler(file_handler)
|
self.logger.addHandler(file_handler)
|
||||||
self.logger.addHandler(console_handler)
|
self.logger.addHandler(console_handler)
|
||||||
|
|
||||||
|
def clear(self):
|
||||||
|
pass
|
||||||
|
|
||||||
def get_functions(self):
|
def get_functions(self):
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user