fix(ai): handle empty response

This commit is contained in:
Udit Karode 2023-04-08 11:08:06 +05:30
parent 7bd82c943c
commit 8258ed9659
No known key found for this signature in database
GPG Key ID: 864BAA48465205F0

View File

@ -37,16 +37,20 @@ export async function ai(ctx: Context<Update>, prompt: string) {
); );
chats[chatId].res = bingRes; chats[chatId].res = bingRes;
let tgRes: FmtString | string; const tgRes = (() => {
if (bingRes.text === prompt) { if (bingRes.text === prompt) {
// Bing Chat often replies with the exact prompt // Bing Chat often replies with the exact prompt
// in case it's unable to continue the conversation. // in case it's unable to continue the conversation.
tgRes = return "Something went wrong. Starting a new chat with /newchat is recommended.";
"Something went wrong. Starting a new chat with /newchat is recommended.";
} else {
tgRes = transformBingResponse(bingRes);
} }
if (!bingRes.text) {
return "Received an empty response. Make sure the bot is set up properly and that you haven't crossed the daily message limit.";
}
return transformBingResponse(bingRes);
})();
await ctx.telegram.editMessageText(chatId, message_id, undefined, tgRes, { await ctx.telegram.editMessageText(chatId, message_id, undefined, tgRes, {
disable_web_page_preview: true, disable_web_page_preview: true,
}); });