VitorFF commited on
Commit
9cad248
·
verified ·
1 Parent(s): 6c1ad3d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -7
app.py CHANGED
@@ -2,14 +2,13 @@ import telebot
2
  import google.generativeai as genai
3
  import os
4
 
5
- # Pega as chaves dos Secrets
6
  TELEGRAM_TOKEN = os.environ.get('TELEGRAM_TOKEN')
7
  GEMINI_KEY = os.environ.get('GEMINI_KEY')
8
  SEU_ID_TELEGRAM = int(os.environ.get('SEU_ID'))
9
 
10
- # Configurando a Inteligência (Jeito atualizado)
11
  genai.configure(api_key=GEMINI_KEY)
12
- # Mudamos aqui para o nome simples que a biblioteca nova exige
 
13
  model = genai.GenerativeModel('gemini-1.5-flash')
14
 
15
  bot = telebot.TeleBot(TELEGRAM_TOKEN)
@@ -19,14 +18,13 @@ def responder(message):
19
  if message.from_user.id != SEU_ID_TELEGRAM:
20
  return
21
  try:
22
- # A IA processa a sua mensagem
23
  response = model.generate_content(message.text)
24
  bot.reply_to(message, response.text)
25
  except Exception as e:
26
- # Se der erro, ele vai te falar exatamente o que é
27
- bot.reply_to(message, f"Erro: {str(e)}")
28
 
29
  if __name__ == "__main__":
30
- print("Assistente Online!")
31
  bot.infinity_polling()
32
 
 
2
  import google.generativeai as genai
3
  import os
4
 
 
5
  TELEGRAM_TOKEN = os.environ.get('TELEGRAM_TOKEN')
6
  GEMINI_KEY = os.environ.get('GEMINI_KEY')
7
  SEU_ID_TELEGRAM = int(os.environ.get('SEU_ID'))
8
 
 
9
  genai.configure(api_key=GEMINI_KEY)
10
+
11
+ # AQUI ESTÁ O SEGREDO: Usamos o modelo estável
12
  model = genai.GenerativeModel('gemini-1.5-flash')
13
 
14
  bot = telebot.TeleBot(TELEGRAM_TOKEN)
 
18
  if message.from_user.id != SEU_ID_TELEGRAM:
19
  return
20
  try:
21
+ # Forçamos a geração sem usar a versão beta que está bugando
22
  response = model.generate_content(message.text)
23
  bot.reply_to(message, response.text)
24
  except Exception as e:
25
+ bot.reply_to(message, "Quase lá! Tenta mandar de novo em 10 segundos.")
26
+ print(f"Erro: {e}")
27
 
28
  if __name__ == "__main__":
 
29
  bot.infinity_polling()
30