Refactor (5)
This commit is contained in:
16
index.ts
16
index.ts
@@ -1,10 +1,16 @@
|
||||
import { parseArgs } from "node:util";
|
||||
import { Stream } from "misskey-js";
|
||||
import type { Note } from "misskey-js/entities.js";
|
||||
import { LlmSession, createGrammar, getModel, parseResponse } from "./lib/llm";
|
||||
import { expandReplyTree, getNotes, me, misskey } from "./lib/misskey";
|
||||
import { sleep } from "./lib/util";
|
||||
import type { ChatHistoryItem, LLamaChatPromptOptions } from "node-llama-cpp";
|
||||
import { LlmSession, createGrammar, getModel, parseResponse } from "./lib/llm";
|
||||
import {
|
||||
expandReplyTree,
|
||||
getNotes,
|
||||
me,
|
||||
misskey,
|
||||
sanitizeText,
|
||||
} from "./lib/misskey";
|
||||
import { sleep } from "./lib/util";
|
||||
|
||||
const { values } = parseArgs({
|
||||
args: Bun.argv,
|
||||
@@ -110,7 +116,7 @@ async function processPostJob() {
|
||||
if (values.test) return;
|
||||
await misskey.request("notes/create", {
|
||||
visibility: "public",
|
||||
text: rephrased,
|
||||
text: sanitizeText(rephrased),
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -142,7 +148,7 @@ async function processReplyJob(job: Extract<Job, { type: "reply" }>) {
|
||||
if (values.test) return;
|
||||
await misskey.request("notes/create", {
|
||||
visibility: job.visibility,
|
||||
text: rephrased,
|
||||
text: sanitizeText(rephrased),
|
||||
replyId: job.id,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -72,3 +72,9 @@ export async function expandReplyTree(
|
||||
}
|
||||
return { last: current, history: history.reverse() };
|
||||
}
|
||||
|
||||
export const sanitizeText = (text: string) =>
|
||||
text
|
||||
.replaceAll(/(\r\n|\r|\n)\s+/g, "\n\n") // remove extra newlines
|
||||
.replaceAll("@", "") // remove mentions
|
||||
.replaceAll("#", ""); // remove hashtags
|
||||
|
||||
Reference in New Issue
Block a user