Discord Bot using model farm isn't working

I’m trying to make an AI discord bot using replit’s model farm but I keep getting internal server errors

import discord
from discord.ext import commands
from replit.ai.modelfarm import ChatExample, ChatMessage, ChatModel, ChatSession

model = ChatModel("chat-bison")
session = ChatSession(
    context="You are philosophy bot.",

    examples=[ChatExample(input=ChatMessage(author="USER", content="what is 1+1?"),
                          output=ChatMessage(author="BOT", content="2"))],

    messages=[
        ChatMessage(author="USER", content="what is 1+1?")
    ]
)


bot = commands.Bot(command_prefix="!", intents=discord.Intents.all())

@bot.event
async def on_message(message):
    if message.author != bot.user:
        session.messages.append(ChatMessage(author="USER", content=message.content))
        
        response = model.chat([
            session
        ], temperature=0.2)
    
        await message.reply(response.responses[-1].candidates[0].message.content)
        
        session.messages.append(ChatMessage(author="BOT", content=response.responses[-1].candidates[0].message.content))

bot.run("my token")```

the error I'm getting is ```Traceback (most recent call last):
  File "/home/runner/ClearRudeIrc-1/.pythonlibs/lib/python3.10/site-packages/discord/client.py", line 441, in _run_event
    await coro(*args, **kwargs)
  File "/home/runner/ClearRudeIrc-1/main.py", line 25, in on_message
    response = model.chat([
  File "/home/runner/ClearRudeIrc-1/.pythonlibs/lib/python3.10/site-packages/replit/ai/modelfarm/chat_model.py", line 53, in chat
    self._check_response(response)
  File "/home/runner/ClearRudeIrc-1/.pythonlibs/lib/python3.10/site-packages/replit/ai/modelfarm/model.py", line 57, in _check_response
    raise InvalidResponseException(rjson["detail"])
replit.ai.modelfarm.exceptions.InvalidResponseException: Internal server error```

Help would be appreciated :)

Hi, do to recent replit updates, you cant directly host a discord bot from your repl. Try deploying it and seeing what happens (You need to pay for deployments). Yes, its quite annoying.

Other than that the code looks fine.

Hi @SachsTheBased !
Are you a Core plan user? If not, you cannot use the Replit AI Modelfarm module.
Hope this helps!

I don’t think @SachsTheBased is referring to Deployments. It was never mentioned anywhere in the post.

1 Like

Yes, but the post was about a discord bot, and people generally want to keep those alive.

1 Like