Use Gemma 4 E2B
This commit is contained in:
66
index.ts
66
index.ts
@@ -67,31 +67,6 @@ const replyJobPrompt = getSystemPrompt(
|
||||
"ユーザがあなたへのメッセージを送ってきています。あるびのちゃんとして、発言に返信してください。",
|
||||
);
|
||||
|
||||
async function rephrase(text: string) {
|
||||
if (
|
||||
text.includes("です") ||
|
||||
text.includes("ます") ||
|
||||
text.includes("でし") ||
|
||||
text.includes("まし") ||
|
||||
text.includes("ません")
|
||||
) {
|
||||
return text;
|
||||
}
|
||||
await using rephraseSession = new LlmSession(
|
||||
model,
|
||||
"ユーザが与えたテキストを「~です」「~ます」調(丁寧な文体)で言い換えたものを、そのまま出力してください。",
|
||||
);
|
||||
await rephraseSession.init();
|
||||
const res = parseResponse(
|
||||
grammar,
|
||||
await rephraseSession.prompt(JSON.stringify({ text }), {
|
||||
...baseChatPromptOptions,
|
||||
customStopTriggers: ["ですます"],
|
||||
}),
|
||||
);
|
||||
return res ?? text;
|
||||
}
|
||||
|
||||
const formatNote = (n: Note) => {
|
||||
if (n.userId === me.id) {
|
||||
return JSON.stringify({ name: "あるびのちゃん", text: n.text });
|
||||
@@ -114,31 +89,29 @@ type Job =
|
||||
history: Note[];
|
||||
};
|
||||
|
||||
await using postJobSession = new LlmSession(model, postJobPrompt);
|
||||
await postJobSession.init();
|
||||
|
||||
async function processPostJob() {
|
||||
const notes = await getNotes(10, 0, 5);
|
||||
const input = notes.map(formatNote).join("\n");
|
||||
const text = await (async () => {
|
||||
await using postJobSession = new LlmSession(model, postJobPrompt);
|
||||
await postJobSession.init();
|
||||
return await parseResponse(
|
||||
grammar,
|
||||
await postJobSession.prompt(input, {
|
||||
...baseChatPromptOptions,
|
||||
temperature: 1.25,
|
||||
minP: 0.05,
|
||||
repeatPenalty: {
|
||||
lastTokens: 128,
|
||||
penalty: 1.15,
|
||||
},
|
||||
}),
|
||||
);
|
||||
})();
|
||||
const text = await parseResponse(
|
||||
grammar,
|
||||
await postJobSession.prompt(input, {
|
||||
...baseChatPromptOptions,
|
||||
temperature: 1.25,
|
||||
minP: 0.05,
|
||||
repeatPenalty: {
|
||||
lastTokens: 128,
|
||||
penalty: 1.15,
|
||||
},
|
||||
}),
|
||||
);
|
||||
if (values.test) return;
|
||||
if (text) {
|
||||
const rephrased = await rephrase(text);
|
||||
if (values.test) return;
|
||||
await misskey.request("notes/create", {
|
||||
visibility: "public",
|
||||
text: sanitizeText(rephrased),
|
||||
text: sanitizeText(text),
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -168,12 +141,11 @@ async function processReplyJob(job: Extract<Job, { type: "reply" }>) {
|
||||
);
|
||||
})();
|
||||
|
||||
if (values.test) return;
|
||||
if (text) {
|
||||
const rephrased = await rephrase(text);
|
||||
if (values.test) return;
|
||||
await misskey.request("notes/create", {
|
||||
visibility: job.visibility,
|
||||
text: sanitizeText(rephrased),
|
||||
text: sanitizeText(text),
|
||||
replyId: job.id,
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user