Add a try/except to the llm

This commit is contained in:
Luke Robles 2024-06-06 08:03:07 -07:00
parent 375bd7ce4b
commit 84984502e7

View File

@ -158,6 +158,7 @@ async def on_message(ctx):
}
headers = {"Content-Type": "application/json"}
try:
await ctx.channel.trigger_typing()
response = requests.post(url, json=payload, headers=headers)
answer = response.json()["choices"][0]["message"]["content"]
@ -167,6 +168,8 @@ async def on_message(ctx):
await ctx.reply(answer[2000:].replace("<|end_of_turn|>", ""))
else:
await ctx.reply(answer.replace("<|end_of_turn|>", ""))
except KeyError:
await ctx.reply("Somethings wrong, maybe the LLM crashed")
bot.run(os.getenv("discord_token"))