Refactor (8)

This commit is contained in:
2026-03-05 09:17:30 +09:00
parent 619cdee636
commit 0d895797f6

View File

@@ -95,22 +95,24 @@ type Job =
}; };
async function processPostJob() { async function processPostJob() {
await using postJobSession = new LlmSession(model, postJobPrompt);
await postJobSession.init();
const notes = await getNotes(10, 0, 5); const notes = await getNotes(10, 0, 5);
const input = notes.map(formatNote).join("\n"); const input = notes.map(formatNote).join("\n");
const text = parseResponse( const text = await (async () => {
grammar, await using postJobSession = new LlmSession(model, postJobPrompt);
await postJobSession.prompt(input, { await postJobSession.init();
...baseChatPromptOptions, return parseResponse(
temperature: 1.0, grammar,
minP: 0.05, await postJobSession.prompt(input, {
repeatPenalty: { ...baseChatPromptOptions,
lastTokens: 128, temperature: 1.0,
penalty: 1.15, minP: 0.05,
}, repeatPenalty: {
}), lastTokens: 128,
); penalty: 1.15,
},
}),
);
})();
if (text) { if (text) {
const rephrased = await rephrase(text); const rephrased = await rephrase(text);
if (values.test) return; if (values.test) return;
@@ -129,20 +131,23 @@ async function processReplyJob(job: Extract<Job, { type: "reply" }>) {
text: formatNote(n), text: formatNote(n),
} as ChatHistoryItem; } as ChatHistoryItem;
}); });
await using session = new LlmSession(model, replyJobPrompt, history); const text = await (async () => {
await session.init(); await using session = new LlmSession(model, replyJobPrompt, history);
const text = parseResponse( await session.init();
grammar, return parseResponse(
await session.prompt(formatNote(job.last), { grammar,
...baseChatPromptOptions, await session.prompt(formatNote(job.last), {
temperature: 0.8, ...baseChatPromptOptions,
minP: 0.1, temperature: 0.8,
repeatPenalty: { minP: 0.1,
lastTokens: 128, repeatPenalty: {
penalty: 1.15, lastTokens: 128,
}, penalty: 1.15,
}), },
); }),
);
})();
if (text) { if (text) {
const rephrased = await rephrase(text); const rephrased = await rephrase(text);
if (values.test) return; if (values.test) return;
@@ -268,6 +273,8 @@ async function test() {
await processJob({ type: "post" }); await processJob({ type: "post" });
await processJob({ type: "post" }); await processJob({ type: "post" });
await processJob({ type: "post" }); await processJob({ type: "post" });
await processJob({ type: "post" });
await processJob({ type: "post" });
} catch (e) { } catch (e) {
console.error(e); console.error(e);
if (e instanceof Error) console.log(e.stack); if (e instanceof Error) console.log(e.stack);