Skip to content

Commit

Permalink
Language hint
Browse files Browse the repository at this point in the history
  • Loading branch information
dahlia committed Jan 13, 2025
1 parent 34670f7 commit fe76118
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
7 changes: 7 additions & 0 deletions bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import "@std/dotenv/load";
import { encodeBase64 } from "@std/encoding/base64";
import { join } from "@std/path/join";
import { AsyncLocalStorage } from "node:async_hooks";
import { detect } from "tinyld";
import { FilterXSS } from "xss";
import metadata from "./deno.json" with { type: "json" };

Expand Down Expand Up @@ -106,9 +107,11 @@ bot.onFollow = async (session, actor) => {
await getIntroMessage(session, actor, await getFollowPrompt(actor)),
]);
const message = response.content.toString();
const language = detect(message);
const md: Text<"block", void> = markdown(message);
await session.publish(
await mentions(session, md, actor) ? md : text`${mention(actor)}\n\n${md}`,
{ language },
);
};

Expand All @@ -121,9 +124,11 @@ bot.onMention = async (session, msg) => {
await getHumanMessage(msg),
]);
const message = response.content.toString();
const language = detect(message);
const md: Text<"block", void> = markdown(message);
await msg.reply(
await mentions(session, md, actor) ? md : text`${mention(actor)}\n\n${md}`,
{ language },
);
};

Expand All @@ -150,11 +155,13 @@ bot.onReply = async (session, msg) => {
}
const response = await llm.invoke(messages);
const message = response.content.toString();
const language = detect(message);
const md: Text<"block", void> = markdown(message);
await msg.reply(
await mentions(session, md, msg.actor)
? md
: text`${mention(msg.actor)}\n\n${md}`,
{ language },
);
};

Expand Down
1 change: 1 addition & 0 deletions deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"@std/dotenv": "jsr:@std/dotenv@^0.225.3",
"@std/encoding": "jsr:@std/encoding@^1.0.6",
"@std/path": "jsr:@std/path@^1.0.8",
"tinyld": "npm:tinyld@^1.3.4",
"xss": "npm:xss@^1.0.15"
},
"unstable": [
Expand Down
5 changes: 5 additions & 0 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit fe76118

Please sign in to comment.