I'm making a discord bot and I want a chat with AI, I don't need a crazy AI that can like solve maths or program for me, just an AI that you can have somewhat of a conversation with. I looked at some free options and tried a bunch of models from hugging face: gpt-neo, gpt-2, DialoGPT, BERT (tried GPT-J but it seems to require too much memory (24GB) to be free) and got absolute non-sense responses, from each of these AIs, the best of them was probably DialoGPT with:
Hello?
Hello? from outer barrel eh?
It could at least maybe say something funny, but nothing that makes sense.
This is my code, maybe I am doing something wrong. If I am not, I'd love to know if there's any free API for what I want.
from discord.ext import commands
import discord
from bot import PDBot
from constants import AI_CHAT_CHANNEL_ID
class AIChat(commands.Cog):
def __init__(self, bot: PDBot):
self.bot: PDBot = bot
self.api_url: str = "https://api-inference.huggingface.co/models/microsoft/DialoGPT-medium"
@commands.Cog.listener()
async def on_message(self, message: discord.Message):
if message.channel.id == AI_CHAT_CHANNEL_ID and not message.author.bot:
payload = {"inputs": message.content}
response = await self.bot.session.post(self.api_url, headers={"Authorization": f"Bearer {self.bot.config.huggingface_token}"}, json=payload)
if response.status == 200:
data = await response.json()
await message.reply(data[0]['generated_text'])
else:
response_content = await response.text()
response_headers = dict(response.headers)
print(f"Response Status Code: {response.status}")
print(f"Response Content: {response_content}")
print(f"Response Headers: {response_headers}")
await message.reply("Sorry, I couldn't fetch a response.")
async def setup(bot):
await bot.add_cog(AIChat(bot))