Add a try/except to the llm
All checks were successful
Build and push / changes (push) Successful in 33s
Build and push / Lint-Python (push) Successful in 6s
Build and push / Build-and-Push-Docker (push) Successful in 1m12s
Build and push / sync-argocd-app (push) Successful in 3s

This commit is contained in:
Luke R 2024-06-06 08:03:07 -07:00
parent c17c5d6dd9
commit 7e4b561a6f

View File

@ -158,15 +158,18 @@ async def on_message(ctx):
}
headers = {"Content-Type": "application/json"}
await ctx.channel.trigger_typing()
response = requests.post(url, json=payload, headers=headers)
answer = response.json()["choices"][0]["message"]["content"]
try:
await ctx.channel.trigger_typing()
response = requests.post(url, json=payload, headers=headers)
answer = response.json()["choices"][0]["message"]["content"]
if len(answer) > 2000:
await ctx.reply(answer[:2000].replace("<|end_of_turn|>", ""))
await ctx.reply(answer[2000:].replace("<|end_of_turn|>", ""))
else:
await ctx.reply(answer.replace("<|end_of_turn|>", ""))
if len(answer) > 2000:
await ctx.reply(answer[:2000].replace("<|end_of_turn|>", ""))
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"))