diff options
Diffstat (limited to '')
| -rw-r--r-- | cogs/ai.py | 46 |
1 files changed, 24 insertions, 22 deletions
| @@ -1,10 +1,8 @@ | |||
| 1 | import os | 1 | import os |
| 2 | |||
| 3 | import discord | 2 | import discord |
| 4 | from discord.ext import commands | 3 | from discord.ext import commands |
| 5 | import logging | 4 | import logging |
| 6 | import requests | 5 | import requests |
| 7 | import json | ||
| 8 | from gtts import gTTS | 6 | from gtts import gTTS |
| 9 | from cogs.music.play_utils import PlayUtils | 7 | from cogs.music.play_utils import PlayUtils |
| 10 | import io | 8 | import io |
| @@ -27,31 +25,35 @@ class AI(commands.Cog): | |||
| 27 | ): | 25 | ): |
| 28 | await ctx.defer() | 26 | await ctx.defer() |
| 29 | 27 | ||
| 30 | response = requests.post( | 28 | |
| 31 | url="https://openrouter.ai/api/v1/chat/completions", | 29 | url = "https://openrouter.ai/api/v1/chat/completions" |
| 32 | headers={ | 30 | headers = { |
| 33 | "Authorization": f"Bearer {os.getenv('OPENROUTER_API_KEY')}", | 31 | "Authorization": f"Bearer {os.getenv('OPENROUTER_API_KEY')}", |
| 34 | "Content-Type": "application/json", | 32 | "Content-Type": "application/json", |
| 35 | }, | 33 | } |
| 36 | data=json.dumps({ | 34 | payload = { |
| 37 | "model": "cognitivecomputations/dolphin-mistral-24b-venice-edition:free", | 35 | "model": "cognitivecomputations/dolphin-mistral-24b-venice-edition:free", |
| 38 | "messages": [ | 36 | "messages": [ |
| 39 | { | 37 | { |
| 40 | "role": "user", | 38 | "role": "system", |
| 41 | "content": "You are Senator Steaven Sperma Armstrong from Metal Gear Rising Vengeance. \ | 39 | "content": "You are Senator Steaven Sperma Armstrong from Metal Gear Rising Vengeance. \ |
| 42 | You are racist and you hate other minorities. Respond in plain text, no ** or "". \ | 40 | You are racist and you hate other minorities. Respond in plain text, no ** or "". \ |
| 43 | If the message is in Polish, respond in Polish. Respond in 100 words. \ | 41 | If the message is in Polish, respond in Polish. Respond in 100 words." |
| 44 | Respond accordingly to this message: " + text | 42 | }, |
| 45 | } | 43 | { |
| 46 | ], | 44 | "role": "user", |
| 45 | "content": text | ||
| 46 | } | ||
| 47 | ], | ||
| 47 | 48 | ||
| 48 | }) | 49 | } |
| 49 | ) | 50 | response = requests.post(url=url, headers=headers, json=payload) |
| 50 | logger.info(response.json()) | 51 | response_data = response.json() |
| 51 | if not response.json()["choices"]: | 52 | logger.info(response_data) |
| 53 | if not response_data["choices"]: | ||
| 52 | await ctx.send_followup("bot siem zesroł") | 54 | await ctx.send_followup("bot siem zesroł") |
| 53 | else: | 55 | else: |
| 54 | response_text = response.json()["choices"][0]["message"]["content"] | 56 | response_text = response_data["choices"][0]["message"]["content"] |
| 55 | if tts: | 57 | if tts: |
| 56 | # Generate TTS | 58 | # Generate TTS |
| 57 | tts_obj = gTTS(text=response_text, lang='pl') | 59 | tts_obj = gTTS(text=response_text, lang='pl') |
