From b1e0eac4b6ee307cf3b1affcae074086348867fd Mon Sep 17 00:00:00 2001 From: salmonik Date: Mon, 19 Jan 2026 10:45:58 +0100 Subject: ai improvements --- cogs/ai.py | 46 ++++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 22 deletions(-) (limited to 'cogs/ai.py') diff --git a/cogs/ai.py b/cogs/ai.py index f527c5b..80e8390 100644 --- a/cogs/ai.py +++ b/cogs/ai.py @@ -1,10 +1,8 @@ import os - import discord from discord.ext import commands import logging import requests -import json from gtts import gTTS from cogs.music.play_utils import PlayUtils import io @@ -27,31 +25,35 @@ class AI(commands.Cog): ): await ctx.defer() - response = requests.post( - url="https://openrouter.ai/api/v1/chat/completions", - headers={ + + url = "https://openrouter.ai/api/v1/chat/completions" + headers = { "Authorization": f"Bearer {os.getenv('OPENROUTER_API_KEY')}", "Content-Type": "application/json", - }, - data=json.dumps({ - "model": "cognitivecomputations/dolphin-mistral-24b-venice-edition:free", - "messages": [ - { - "role": "user", - "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 - } - ], + } + payload = { + "model": "cognitivecomputations/dolphin-mistral-24b-venice-edition:free", + "messages": [ + { + "role": "system", + "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." + }, + { + "role": "user", + "content": text + } + ], - }) - ) - logger.info(response.json()) - if not response.json()["choices"]: + } + response = requests.post(url=url, headers=headers, json=payload) + response_data = response.json() + logger.info(response_data) + if not response_data["choices"]: await ctx.send_followup("bot siem zesroĊ‚") else: - response_text = response.json()["choices"][0]["message"]["content"] + response_text = response_data["choices"][0]["message"]["content"] if tts: # Generate TTS tts_obj = gTTS(text=response_text, lang='pl') -- cgit v1.2.3