Skip to content

Commit fe76118

Browse files
committed
Language hint
1 parent 34670f7 commit fe76118

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

bot.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import "@std/dotenv/load";
4444
import { encodeBase64 } from "@std/encoding/base64";
4545
import { join } from "@std/path/join";
4646
import { AsyncLocalStorage } from "node:async_hooks";
47+
import { detect } from "tinyld";
4748
import { FilterXSS } from "xss";
4849
import metadata from "./deno.json" with { type: "json" };
4950

@@ -106,9 +107,11 @@ bot.onFollow = async (session, actor) => {
106107
await getIntroMessage(session, actor, await getFollowPrompt(actor)),
107108
]);
108109
const message = response.content.toString();
110+
const language = detect(message);
109111
const md: Text<"block", void> = markdown(message);
110112
await session.publish(
111113
await mentions(session, md, actor) ? md : text`${mention(actor)}\n\n${md}`,
114+
{ language },
112115
);
113116
};
114117

@@ -121,9 +124,11 @@ bot.onMention = async (session, msg) => {
121124
await getHumanMessage(msg),
122125
]);
123126
const message = response.content.toString();
127+
const language = detect(message);
124128
const md: Text<"block", void> = markdown(message);
125129
await msg.reply(
126130
await mentions(session, md, actor) ? md : text`${mention(actor)}\n\n${md}`,
131+
{ language },
127132
);
128133
};
129134

@@ -150,11 +155,13 @@ bot.onReply = async (session, msg) => {
150155
}
151156
const response = await llm.invoke(messages);
152157
const message = response.content.toString();
158+
const language = detect(message);
153159
const md: Text<"block", void> = markdown(message);
154160
await msg.reply(
155161
await mentions(session, md, msg.actor)
156162
? md
157163
: text`${mention(msg.actor)}\n\n${md}`,
164+
{ language },
158165
);
159166
};
160167

deno.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"@std/dotenv": "jsr:@std/dotenv@^0.225.3",
1515
"@std/encoding": "jsr:@std/encoding@^1.0.6",
1616
"@std/path": "jsr:@std/path@^1.0.8",
17+
"tinyld": "npm:tinyld@^1.3.4",
1718
"xss": "npm:xss@^1.0.15"
1819
},
1920
"unstable": [

deno.lock

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)