Add Telegram bot support #23

Merged
Berack96 merged 23 commits from 6-telegram-interface into main 2025-10-13 10:49:46 +02:00
4 changed files with 16 additions and 9 deletions
Showing only changes of commit 01fbd5607c - Show all commits

View File

@@ -1,4 +1,3 @@
# IMPORTANTE: Carichiamo le variabili d'ambiente PRIMA di qualsiasi altra cosa
import asyncio
import logging
from dotenv import load_dotenv
@@ -8,7 +7,6 @@ from app.agents import Pipeline
if __name__ == "__main__":
# Inizializzazioni
load_dotenv()
configs = AppConfig.load()
@@ -23,8 +21,11 @@ if __name__ == "__main__":
telegram = TelegramApp(pipeline)
telegram.add_miniapp_url(share_url)
telegram.run()
except Exception as _:
logging.warning("Telegram bot could not be started. Continuing without it.")
asyncio.get_event_loop().run_forever()
except AssertionError as e:
try:
logging.warning(f"Telegram bot could not be started: {e}")
asyncio.get_event_loop().run_forever()
except KeyboardInterrupt:
logging.info("Shutting down due to KeyboardInterrupt")
finally:
gradio.close()

View File

@@ -3,7 +3,7 @@ from app.agents.team import create_team_with
from app.agents.prompts import *
from app.configs import AppConfig
logging = logging.getLogger(__name__)
logging = logging.getLogger("pipeline")
class Pipeline:
@@ -30,6 +30,12 @@ class Pipeline:
"""
self.leader_model = self.configs.models.all_models[index]
def choose_team(self, index: int):
"""
Sceglie il modello LLM da usare per il Team.
"""
self.team_model = self.configs.models.all_models[index]
def choose_strategy(self, index: int):
"""
Sceglie la strategia da usare per il Predictor.

View File

@@ -4,7 +4,7 @@ import time
import traceback
from typing import Any, Callable, Generic, TypeVar
logging = logging.getLogger(__name__)
logging = logging.getLogger("wrapper_handler")
WrapperType = TypeVar("WrapperType")
WrapperClassType = TypeVar("WrapperClassType")
OutputType = TypeVar("OutputType")

View File

@@ -14,7 +14,7 @@ from app.configs import AppConfig
# per per_message di ConversationHandler che rompe sempre qualunque input tu metta
warnings.filterwarnings("ignore")
logging = logging.getLogger(__name__)
logging = logging.getLogger("telegram")
# Lo stato cambia in base al valore di ritorno delle funzioni async
@@ -69,7 +69,7 @@ class TelegramApp:
})}
httpx.post(endpoint, data=payload)
except httpx.HTTPError as e:
logging.info(f"Failed to update mini app URL: {e}")
logging.warning(f"Failed to update mini app URL: {e}")
def create_bot(self) -> None:
"""