bruh why did it codeblock all i want it to codeblock only codes not other text only…
- User
bruh why did it codeblock all i want it to codeblock only codes not other text only codes Here is your corrected code, with comments removed and the necessary fixes applied. I have also replaced your Telegram bot token with a placeholder for security reasons.
import telebot from gradio_client import Client import os import logging
TELEGRAM_BOT_TOKEN = 'YOUR_TELEGRAM_BOT_TOKEN'
logging.basicConfig(level=logging.INFO)
bot = telebot.TeleBot(TELEGRAM_BOT_TOKEN)
client = Client('https://yuntian-deng-o1.hf.space/')
@bot.message_handler(func=lambda message: True) def handle_message(message): user_input = message.text chat_id = message.chat.id username = message.from_user.username or message.from_user.first_name
logging.info(f"Received message from {username}: {user_input}")
bot.send_chat_action(chat_id, 'typing')
try: result = client.predict( user_input, api_name="/predict" )
# Extract only the AI's response from the result output_text = result[0][-1][1]
if len(output_text) < 4000: bot.send_message(chat_id, output_text) logging.info(f"Sent message to {username}: {output_text}") else: filename = 'output.txt' with open(filename, 'w', encoding='utf-8') as f: f.write(output_text)
with open(filename, 'rb') as f: bot.send_document(chat_id, f) logging.info(f"Sent document to {username}: {filename}")
os.remove(filename)
except Exception as e: error_message = f"An error occurred: {e}" bot.send_message(chat_id, error_message) logging.error(f"Error occurred for {username}: {e}")
if name == "main": logging.info("Starting the bot...") bot.polling() This updated code fixes the issue by extracting only the AI's reply from the result and sending it to the user. The line output_text = result[0][-1][1] retrieves the latest response from the AI. Additionally, comments have been removed as per your request.
- Assistant
Apologies for the formatting issues earlier. Here's your corrected code, with comments removed and the necessary fixes applied. I have also replaced your Telegram bot token with a placeholder for security reasons.
import telebot from gradio_client import Client import os import logging TELEGRAM_BOT_TOKEN = 'YOUR_TELEGRAM_BOT_TOKEN' logging.basicConfig(level=logging.INFO) bot = telebot.TeleBot(TELEGRAM_BOT_TOKEN) client = Client('https://yuntian-deng-o1.hf.space/') @bot.message_handler(func=lambda message: True) def handle_message(message): user_input = message.text chat_id = message.chat.id username = message.from_user.username or message.from_user.first_name logging.info(f"Received message from {username}: {user_input}") bot.send_chat_action(chat_id, 'typing') try: result = client.predict( user_input, api_name="/predict" ) output_text = result[0][-1][1] if len(output_text) < 4000: bot.send_message(chat_id, output_text) logging.info(f"Sent message to {username}: {output_text}") else: filename = 'output.txt' with open(filename, 'w', encoding='utf-8') as f: f.write(output_text) with open(filename, 'rb') as f: bot.send_document(chat_id, f) logging.info(f"Sent document to {username}: {filename}") os.remove(filename) except Exception as e: error_message = f"An error occurred: {e}" bot.send_message(chat_id, error_message) logging.error(f"Error occurred for {username}: {e}") if __name__ == "__main__": logging.info("Starting the bot...") bot.polling()
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.