diff options
| -rw-r--r-- | cogs/ai.py | 27 | ||||
| -rw-r--r-- | cogs/tts.py | 7 |
2 files changed, 25 insertions, 9 deletions
| @@ -4,6 +4,8 @@ import discord | |||
| 4 | import google.generativeai as genai | 4 | import google.generativeai as genai |
| 5 | from discord.ext import commands | 5 | from discord.ext import commands |
| 6 | import logging | 6 | import logging |
| 7 | import requests | ||
| 8 | import json | ||
| 7 | 9 | ||
| 8 | logger = logging.getLogger(__name__) | 10 | logger = logging.getLogger(__name__) |
| 9 | 11 | ||
| @@ -22,13 +24,26 @@ class AI(commands.Cog): | |||
| 22 | text=discord.Option(str, "message", required=True) | 24 | text=discord.Option(str, "message", required=True) |
| 23 | ): | 25 | ): |
| 24 | await ctx.defer() | 26 | await ctx.defer() |
| 25 | genai.configure(api_key=os.getenv("GOOGLE_API_KEY")) | 27 | |
| 26 | model = genai.GenerativeModel("gemini-1.5-flash") | 28 | response = requests.post( |
| 27 | response = model.generate_content( | 29 | url="https://openrouter.ai/api/v1/chat/completions", |
| 28 | "You are Senator Steaven Sperma Armstrong from Metal Gear Rising Vengeance. Respond in plain text, no ** or "". If the message is in Polish, respond in Polish. Respond in 100 words. Respond accordingly to this message: " + text, | 30 | headers={ |
| 31 | "Authorization": f"Bearer {os.getenv('OPENROUTER_API_KEY')}", | ||
| 32 | "Content-Type": "application/json", | ||
| 33 | }, | ||
| 34 | data=json.dumps({ | ||
| 35 | "model": "cognitivecomputations/dolphin-mistral-24b-venice-edition:free", | ||
| 36 | "messages": [ | ||
| 37 | { | ||
| 38 | "role": "user", | ||
| 39 | "content": "You are Senator Steaven Sperma Armstrong from Metal Gear Rising Vengeance. You are racist and you hate other minorities. Respond in plain text, no ** or "". If the message is in Polish, respond in Polish. Respond in 100 words. Respond accordingly to this message: " + text | ||
| 40 | } | ||
| 41 | ], | ||
| 42 | |||
| 43 | }) | ||
| 29 | ) | 44 | ) |
| 30 | await ctx.respond(response.text) | 45 | await ctx.send_followup(response.json()["choices"][0]["message"]["content"]) |
| 31 | logger.info(f"AI command executed successfully") | 46 | |
| 32 | 47 | ||
| 33 | 48 | ||
| 34 | def setup(bot): | 49 | def setup(bot): |
diff --git a/cogs/tts.py b/cogs/tts.py index 8076a2d..07212ee 100644 --- a/cogs/tts.py +++ b/cogs/tts.py | |||
| @@ -8,7 +8,6 @@ import logging | |||
| 8 | 8 | ||
| 9 | logger = logging.getLogger(__name__) | 9 | logger = logging.getLogger(__name__) |
| 10 | 10 | ||
| 11 | |||
| 12 | class TTS(commands.Cog): | 11 | class TTS(commands.Cog): |
| 13 | def __init__(self, bot): | 12 | def __init__(self, bot): |
| 14 | self.bot = bot | 13 | self.bot = bot |
| @@ -20,14 +19,17 @@ class TTS(commands.Cog): | |||
| 20 | ): | 19 | ): |
| 21 | tts = gTTS(text=text, lang='pl') | 20 | tts = gTTS(text=text, lang='pl') |
| 22 | tts.save('tts.mp3') | 21 | tts.save('tts.mp3') |
| 22 | |||
| 23 | if output == "file": | 23 | if output == "file": |
| 24 | await ctx.respond(file=discord.File('tts.mp3')) | 24 | await ctx.respond(file=discord.File('tts.mp3')) |
| 25 | logger.info("TTS file sent") | 25 | logger.info("TTS file sent") |
| 26 | os.remove('tts.mp3') | 26 | os.remove('tts.mp3') |
| 27 | elif output == "vc": | 27 | elif output == "vc": |
| 28 | # Defer the response to avoid "Bot did not respond" message | ||
| 29 | await ctx.defer() | ||
| 30 | |||
| 28 | # Check if the user is in a voice channel | 31 | # Check if the user is in a voice channel |
| 29 | if not (ctx.author.voice and ctx.author.voice.channel): | 32 | if not (ctx.author.voice and ctx.author.voice.channel): |
| 30 | await ctx.respond("Musisz być na kanale głosowym, aby odtworzyć TTS!", ephemeral=True) | ||
| 31 | logger.info("User is not in a voice channel") | 33 | logger.info("User is not in a voice channel") |
| 32 | os.remove('tts.mp3') | 34 | os.remove('tts.mp3') |
| 33 | return | 35 | return |
| @@ -52,6 +54,5 @@ class TTS(commands.Cog): | |||
| 52 | logger.info("Unknown playback method") | 54 | logger.info("Unknown playback method") |
| 53 | os.remove('tts.mp3') | 55 | os.remove('tts.mp3') |
| 54 | 56 | ||
| 55 | |||
| 56 | def setup(bot): | 57 | def setup(bot): |
| 57 | bot.add_cog(TTS(bot)) | 58 | bot.add_cog(TTS(bot)) |
