Refactor
This commit is contained in:
18
index.ts
18
index.ts
@@ -64,6 +64,7 @@ const getSystemPrompt = (
|
||||
- 「~です」「~ます」などの語尾を使って **丁寧に** 話す。
|
||||
- ハッシュタグや絵文字を使わない。
|
||||
- \`{ name: string, text: string }\` の JSON 形式で出力する。name と text 以外のプロパティは出力しない。
|
||||
- 3センテンス、140文字程度で出力する。
|
||||
|
||||
${instruction}`;
|
||||
const postJobPrompt = getSystemPrompt(
|
||||
@@ -74,6 +75,15 @@ 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,
|
||||
"ユーザが与えたテキストを「~です」「~ます」調(丁寧な文体)で言い換えたものを、そのまま出力してください。",
|
||||
@@ -111,12 +121,13 @@ 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 parseResponse(
|
||||
const text = await (async () => {
|
||||
await using postJobSession = new LlmSession(model, postJobPrompt);
|
||||
await postJobSession.init();
|
||||
return await parseResponse(
|
||||
grammar,
|
||||
await postJobSession.prompt(input, {
|
||||
...baseChatPromptOptions,
|
||||
@@ -128,6 +139,7 @@ async function processPostJob() {
|
||||
},
|
||||
}),
|
||||
);
|
||||
})();
|
||||
if (text) {
|
||||
const rephrased = await rephrase(text);
|
||||
if (values.test) return;
|
||||
|
||||
Reference in New Issue
Block a user