Add a try/except to the llm
This commit is contained in:
parent
375bd7ce4b
commit
84984502e7
19
app/bot.py
19
app/bot.py
@ -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"))
|
||||
|
Loading…
x
Reference in New Issue
Block a user