Spaces:
Runtime error
Runtime error
Update main.py
Browse files123456789101112133 unmodified lines17181920212223242513 unmodified lines394041424344452 unmodified lines4849505152535455565758import osimport discordfrom discord.ext import commandsimport google.generativeai as genai# Configurar las claves secretasDISCORD_TOKEN = os.getenv("DISCORD_TOKEN")GEMINI_API_KEY = os.getenv("GEMINI_API_KEY")genai.configure(api_key=GEMINI_API_KEY)# Configurar la personalidad y la jerga del botPERSONALIDAD = (3 unmodified lines"Sos un par, un amigo más del grupo.")model = genai.GenerativeModel(model_name="gemini-1.5-flash",system_instruction=PERSONALIDAD)# Configurar permisos del bot de Discord13 unmodified lines# Responder solo si mencionan al botif bot.user in message.mentions:# Limpiar la mención del texto para que no confunda a la IAtexto_usuario = message.content.replace(f'<@!{bot.user.id}>', '').replace(f'<@{bot.user.id}>', '').strip()if not texto_usuario:2 unmodified linesasync with message.channel.typing():try:response = model.generate_content(texto_usuario)await message.reply(response.text)except Exception as e:print(f"Error: {e}")await message.reply("Uhh bld, se me cruzaron los cables, aguantame un toque.")await bot.process_commands(message)1234567891011121314153 unmodified lines19202122232425262713 unmodified lines414243444546472 unmodified lines50515253545556575859606162636465import osimport discordfrom discord.ext import commandsfrom google import genaifrom google.genai import types# Configurar las claves secretasDISCORD_TOKEN = os.getenv("DISCORD_TOKEN")GEMINI_API_KEY = os.getenv("GEMINI_API_KEY")# Inicializar el cliente nuevo de Geminiclient = genai.Client(api_key=GEMINI_API_KEY)# Configurar la personalidad y la jerga del botPERSONALIDAD = (3 unmodified lines"Sos un par, un amigo más del grupo.")config = types.GenerateContentConfig(system_instruction=PERSONALIDAD,model="gemini-1.5-flash")# Configurar permisos del bot de Discord13 unmodified lines# Responder solo si mencionan al botif bot.user in message.mentions:# Limpiar la mención del textotexto_usuario = message.content.replace(f'<@!{bot.user.id}>', '').replace(f'<@{bot.user.id}>', '').strip()if not texto_usuario:2 unmodified linesasync with message.channel.typing():try:# Usar el método nuevo del clienteresponse = client.models.generate_content(model="gemini-1.5-flash",contents=texto_usuario,config=config)await message.reply(response.text)except Exception as e:print(f"Error real en la API: {e}")await message.reply("Uhh bld, se me cruzaron los cables en serio, aguantame un toque.")await bot.process_commands(message)
main.py+16-9