Refactor (9)

This commit is contained in:
2026-03-05 22:59:05 +09:00
parent 0d895797f6
commit f61298f9e4
2 changed files with 20 additions and 2 deletions

View File

@@ -2,7 +2,13 @@ import { parseArgs } from "node:util";
import { Stream } from "misskey-js";
import type { Note } from "misskey-js/entities.js";
import type { ChatHistoryItem, LLamaChatPromptOptions } from "node-llama-cpp";
import { LlmSession, createGrammar, getModel, parseResponse } from "./lib/llm";
import {
LlmSession,
createBias,
createGrammar,
getModel,
parseResponse,
} from "./lib/llm";
import {
expandReplyTree,
getNotes,
@@ -30,9 +36,11 @@ const modelName =
console.log(`* loading model '${modelName}'`);
const model = await getModel(modelName);
const grammar = await createGrammar("あるびのちゃん");
const bias = createBias(model);
const baseChatPromptOptions = {
grammar,
maxTokens: 256,
tokenBias: bias,
} as const satisfies LLamaChatPromptOptions;
const getSystemPrompt = (
@@ -58,7 +66,7 @@ async function rephrase(text: string) {
await using rephraseSession = new LlmSession(
model,
getSystemPrompt(
"user が与えたテキストを『ですます調』(丁寧な文体)で言い換えたものを、そのまま出力してください。",
"ユーザが与えたテキストを「~です」「~ます」調(丁寧な文体)で言い換えたものを、そのまま出力してください。",
),
);
await rephraseSession.init();