From 08cb9f35e21b13f61525e1339f3a4414ba7bd0f3 Mon Sep 17 00:00:00 2001 From: powermaker450 Date: Fri, 21 Jun 2024 14:37:58 +0000 Subject: [PATCH] Fix support for all markdown formatting --- src/bot.ts | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/src/bot.ts b/src/bot.ts index 0fe7f6b..f2ef197 100644 --- a/src/bot.ts +++ b/src/bot.ts @@ -32,7 +32,7 @@ if (!allVarsFilled) { const session: Messages = checkFile("./messages.json", "utf-8", system.normal); console.log("Our conversation is:", session); -const THINKING = "[markdown]`Thinking...`[/markdown]"; +const THINKING = "[md]`Thinking...`[/md]"; const assistant = new OpenAI({ baseURL: endpoint, @@ -71,7 +71,7 @@ client.connect().then(async () => { await client.sendMessage({ converseId: message.converseId, groupId: message.groupId, - content: "[markdown]`Generating image...`[/markdown]", + content: "[md]`Generating image...`[/md]", }); const imageRequest: ImageRequestData = { @@ -108,7 +108,7 @@ client.connect().then(async () => { content: [ { type: "text", - text: `${username} said: Describe what you think is in this image.`, + text: `${username} said: Describe what is in this image.`, }, { type: "image_url", @@ -137,12 +137,8 @@ client.connect().then(async () => { converseId: message.converseId, groupId: message.groupId, // @ts-ignore - content: response.choices - .at(0) - // Replace all the ** at the beginning and end of texts with the corresponding Tailchat bold tags. - // Tailchat doesn't support these tags. I'll probably implement a regex for the other tags later. - .message.content.replaceAll(/([^\s\S]?)(\*\*)(?=\w)/g, " [b]") - .replaceAll(/(\*\*)/g, "[/b]"), + // Surround in [md] tags to support markdown formatting. + content: `[md]${response.choices.at(0)}[/md]`, }); fs.writeFileSync("./messages.json", JSON.stringify(session), "utf8"); @@ -175,11 +171,8 @@ client.connect().then(async () => { converseId: message.converseId, groupId: message.groupId, // @ts-ignore - content: response.choices - .at(0) - // Same as above. Replace ** with bold tags for Tailchat - .message.content.replaceAll(/([^\s\S]?)(\*\*)(?=\w)/g, " [b]") - .replaceAll(/(\*\*)/g, "[/b]"), + // Same as above. Surround with [md] tags to support markdown formatting. + content: `[md]${response.choices.at(0)}[/md]`, }); fs.writeFileSync("./messages.json", JSON.stringify(session), "utf8"); @@ -221,10 +214,7 @@ client.connect().then(async () => { await client.sendMessage({ converseId: message.converseId, // @ts-ignore - content: response.choices - .at(0) - .message.content.replaceAll(/([^\s\S]?)(\*\*)(?=\w)/g, " [b]") - .replaceAll(/(\*\*)/g, "[/b]"), + content: `[md]${response.choices.at(0)}[/md]`, }); fs.writeFileSync("./messages.json", JSON.stringify(session), "utf8");