Fix support for all markdown formatting

This commit is contained in:
powermaker450 2024-06-21 14:37:58 +00:00
parent d619b495a4
commit 08cb9f35e2

View file

@ -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");