Refactor (8)

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

View File

@@ -95,11 +95,12 @@ 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 () => {
await using postJobSession = new LlmSession(model, postJobPrompt);
await postJobSession.init();
return parseResponse(
grammar, grammar,
await postJobSession.prompt(input, { await postJobSession.prompt(input, {
...baseChatPromptOptions, ...baseChatPromptOptions,
@@ -111,6 +112,7 @@ async function processPostJob() {
}, },
}), }),
); );
})();
if (text) { if (text) {
const rephrased = await rephrase(text); const rephrased = await rephrase(text);
if (values.test) return; if (values.test) return;
@@ -129,9 +131,10 @@ async function processReplyJob(job: Extract<Job, { type: "reply" }>) {
text: formatNote(n), text: formatNote(n),
} as ChatHistoryItem; } as ChatHistoryItem;
}); });
const text = await (async () => {
await using session = new LlmSession(model, replyJobPrompt, history); await using session = new LlmSession(model, replyJobPrompt, history);
await session.init(); await session.init();
const text = parseResponse( return parseResponse(
grammar, grammar,
await session.prompt(formatNote(job.last), { await session.prompt(formatNote(job.last), {
...baseChatPromptOptions, ...baseChatPromptOptions,
@@ -143,6 +146,8 @@ async function processReplyJob(job: Extract<Job, { type: "reply" }>) {
}, },
}), }),
); );
})();
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);