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); const session: Messages = checkFile("./messages.json", "utf-8", system.normal);
console.log("Our conversation is:", session); console.log("Our conversation is:", session);
const THINKING = "[markdown]`Thinking...`[/markdown]"; const THINKING = "[md]`Thinking...`[/md]";
const assistant = new OpenAI({ const assistant = new OpenAI({
baseURL: endpoint, baseURL: endpoint,
@ -71,7 +71,7 @@ client.connect().then(async () => {
await client.sendMessage({ await client.sendMessage({
converseId: message.converseId, converseId: message.converseId,
groupId: message.groupId, groupId: message.groupId,
content: "[markdown]`Generating image...`[/markdown]", content: "[md]`Generating image...`[/md]",
}); });
const imageRequest: ImageRequestData = { const imageRequest: ImageRequestData = {
@ -108,7 +108,7 @@ client.connect().then(async () => {
content: [ content: [
{ {
type: "text", 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", type: "image_url",
@ -137,12 +137,8 @@ client.connect().then(async () => {
converseId: message.converseId, converseId: message.converseId,
groupId: message.groupId, groupId: message.groupId,
// @ts-ignore // @ts-ignore
content: response.choices // Surround in [md] tags to support markdown formatting.
.at(0) content: `[md]${response.choices.at(0)}[/md]`,
// 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]"),
}); });
fs.writeFileSync("./messages.json", JSON.stringify(session), "utf8"); fs.writeFileSync("./messages.json", JSON.stringify(session), "utf8");
@ -175,11 +171,8 @@ client.connect().then(async () => {
converseId: message.converseId, converseId: message.converseId,
groupId: message.groupId, groupId: message.groupId,
// @ts-ignore // @ts-ignore
content: response.choices // Same as above. Surround with [md] tags to support markdown formatting.
.at(0) content: `[md]${response.choices.at(0)}[/md]`,
// Same as above. Replace ** with bold tags for Tailchat
.message.content.replaceAll(/([^\s\S]?)(\*\*)(?=\w)/g, " [b]")
.replaceAll(/(\*\*)/g, "[/b]"),
}); });
fs.writeFileSync("./messages.json", JSON.stringify(session), "utf8"); fs.writeFileSync("./messages.json", JSON.stringify(session), "utf8");
@ -221,10 +214,7 @@ client.connect().then(async () => {
await client.sendMessage({ await client.sendMessage({
converseId: message.converseId, converseId: message.converseId,
// @ts-ignore // @ts-ignore
content: response.choices content: `[md]${response.choices.at(0)}[/md]`,
.at(0)
.message.content.replaceAll(/([^\s\S]?)(\*\*)(?=\w)/g, " [b]")
.replaceAll(/(\*\*)/g, "[/b]"),
}); });
fs.writeFileSync("./messages.json", JSON.stringify(session), "utf8"); fs.writeFileSync("./messages.json", JSON.stringify(session), "utf8");