From 0d895797f6992f868cd864c7b9c211c632a4f369 Mon Sep 17 00:00:00 2001 From: cannorin Date: Thu, 5 Mar 2026 09:17:30 +0900 Subject: [PATCH] Refactor (8) --- index.ts | 63 +++++++++++++++++++++++++++++++------------------------- 1 file changed, 35 insertions(+), 28 deletions(-) diff --git a/index.ts b/index.ts index 580c742..0770319 100644 --- a/index.ts +++ b/index.ts @@ -95,22 +95,24 @@ type Job = }; async function processPostJob() { - await using postJobSession = new LlmSession(model, postJobPrompt); - await postJobSession.init(); const notes = await getNotes(10, 0, 5); const input = notes.map(formatNote).join("\n"); - const text = parseResponse( - grammar, - await postJobSession.prompt(input, { - ...baseChatPromptOptions, - temperature: 1.0, - minP: 0.05, - repeatPenalty: { - lastTokens: 128, - penalty: 1.15, - }, - }), - ); + const text = await (async () => { + await using postJobSession = new LlmSession(model, postJobPrompt); + await postJobSession.init(); + return parseResponse( + grammar, + await postJobSession.prompt(input, { + ...baseChatPromptOptions, + temperature: 1.0, + minP: 0.05, + repeatPenalty: { + lastTokens: 128, + penalty: 1.15, + }, + }), + ); + })(); if (text) { const rephrased = await rephrase(text); if (values.test) return; @@ -129,20 +131,23 @@ async function processReplyJob(job: Extract) { text: formatNote(n), } as ChatHistoryItem; }); - await using session = new LlmSession(model, replyJobPrompt, history); - await session.init(); - const text = parseResponse( - grammar, - await session.prompt(formatNote(job.last), { - ...baseChatPromptOptions, - temperature: 0.8, - minP: 0.1, - repeatPenalty: { - lastTokens: 128, - penalty: 1.15, - }, - }), - ); + const text = await (async () => { + await using session = new LlmSession(model, replyJobPrompt, history); + await session.init(); + return parseResponse( + grammar, + await session.prompt(formatNote(job.last), { + ...baseChatPromptOptions, + temperature: 0.8, + minP: 0.1, + repeatPenalty: { + lastTokens: 128, + penalty: 1.15, + }, + }), + ); + })(); + if (text) { const rephrased = await rephrase(text); 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" }); } catch (e) { console.error(e); if (e instanceof Error) console.log(e.stack);