fix(ai): avoid unnecessarily transforming response

This commit is contained in:
Udit Karode 2023-04-08 11:01:33 +05:30
parent 5d54cdf386
commit 23e78dbb81
No known key found for this signature in database
GPG Key ID: 864BAA48465205F0

View File

@ -3,7 +3,7 @@ import { done, firstPos, queue } from "./queue.js";
import { transformBingResponse } from "./transformers.js"; import { transformBingResponse } from "./transformers.js";
import { ChatMessage } from "bing-chat"; import { ChatMessage } from "bing-chat";
import { Context } from "telegraf"; import { Context } from "telegraf";
import { bold, fmt } from "telegraf/format"; import { FmtString, bold, fmt } from "telegraf/format";
import { Update } from "typegram"; import { Update } from "typegram";
const chats: Record< const chats: Record<
@ -37,12 +37,13 @@ export async function ai(ctx: Context<Update>, prompt: string) {
); );
chats[chatId].res = bingRes; chats[chatId].res = bingRes;
let tgRes = transformBingResponse(bingRes); let tgRes: FmtString;
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.
if (tgRes.text === prompt && !tgRes.entities) {
tgRes = fmt`Something went wrong. Starting a new chat with /newchat is recommended.`; tgRes = fmt`Something went wrong. Starting a new chat with /newchat is recommended.`;
} else {
tgRes = transformBingResponse(bingRes);
} }
await ctx.telegram.editMessageText(chatId, message_id, undefined, tgRes, { await ctx.telegram.editMessageText(chatId, message_id, undefined, tgRes, {