mirror of
https://github.com/uditkarode/bing-chat-telegram.git
synced 2025-02-22 09:12:21 +00:00
fix(ai): handle empty response
This commit is contained in:
parent
7bd82c943c
commit
8258ed9659
22
src/ai.ts
22
src/ai.ts
@ -37,15 +37,19 @@ export async function ai(ctx: Context<Update>, prompt: string) {
|
||||
);
|
||||
chats[chatId].res = bingRes;
|
||||
|
||||
let tgRes: FmtString | string;
|
||||
if (bingRes.text === prompt) {
|
||||
// Bing Chat often replies with the exact prompt
|
||||
// in case it's unable to continue the conversation.
|
||||
tgRes =
|
||||
"Something went wrong. Starting a new chat with /newchat is recommended.";
|
||||
} else {
|
||||
tgRes = transformBingResponse(bingRes);
|
||||
}
|
||||
const tgRes = (() => {
|
||||
if (bingRes.text === prompt) {
|
||||
// Bing Chat often replies with the exact prompt
|
||||
// in case it's unable to continue the conversation.
|
||||
return "Something went wrong. Starting a new chat with /newchat is recommended.";
|
||||
}
|
||||
|
||||
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, {
|
||||
disable_web_page_preview: true,
|
||||
|
Loading…
x
Reference in New Issue
Block a user