import logging import os import sys import threading sys.path.insert(0, "src") os.environ['TRANSFORMERS_CACHE'] = '/tmp' from telegram.ext import ( CommandHandler, CallbackContext, Application, ContextTypes, ) from api import GirlfriendGPT from functools import partial from typing import List from telegram import Update from termcolor import colored SELECT_COMMAND, GET_TEXT = range(2) # Enable logging logging.basicConfig( format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", level=logging.INFO ) logger = logging.getLogger(__name__) # def show_results(response_messages): # print(colored("\nResults: ", "blue", attrs=["bold"])) # for message in response_messages: # if message.mime_type: # print(message.url, end="\n\n") # else: # print(message.text, end="\n\n") def shutdown(updater: Update): updater.stop() updater.is_idle = False def stop(update): threading.Thread(target=shutdown(updater=update)).start() async def hello(update: Update, context: CallbackContext) -> None: intro_text = f"šŸ¤– Greetings human!šŸ¤—\nI'm a bot built by Rexthecoder\nšŸ¦¾ I can do a lot of things" await update.message.reply_text(intro_text) # async def echo(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int: # """Echo the user message.""" # await update.message.reply_text("Enter your text") # return GET_TEXT class LoggingDisabled: """Context manager that turns off logging within context.""" def __enter__(self): logging.disable(logging.CRITICAL) def __exit__(self, exit_type, exit_value, exit_traceback): logging.disable(logging.NOTSET) def main(): app = Application.builder().token( '6207542226:AAEoNVXw766dq8fYqVvBQW9Hve2Rovq0ERI',).build() # application = Application.builder().token('6207542226:AAGXBVVxNNUKLUz17-5_sGJnhFDaVWUXTc8').build() # application.add_handler(CommandHandler('start', hello)) # # Run the bot until the user presses Ctrl-C # application.run_polling() run_agent( agent=GirlfriendGPT( token="hello", application=app ) ) print(f"Starting Agent...") def run_agent(agent: GirlfriendGPT, as_api: bool = False) -> None: # For Debugging summary_handler = agent.conversation_summary_handler() agent.application.add_handler(summary_handler) agent.application.add_handler(CommandHandler('stop', stop)) agent.application.add_handler(CommandHandler('start', hello)) # agent.application.add_handler(CommandHandler('summary', agent.conversation_summary)) # agent.application.add_handler(MessageHandler( # filters.TEXT & ~filters.COMMAND, agent.create_response)) agent.application.run_polling() # agent.application.add_handler(MessageHandler( # filters.TEXT & ~filters.COMMAND, agent.create_response)) if __name__ == "__main__": main()