Refactor
This commit is contained in:
17
index.ts
17
index.ts
@@ -2,7 +2,7 @@ import { parseArgs } from "node:util";
|
||||
import { Stream } from "misskey-js";
|
||||
import type { Note } from "misskey-js/entities.js";
|
||||
import type { ChatHistoryItem, LLamaChatPromptOptions } from "node-llama-cpp";
|
||||
import { LlmSession, createGrammar, getModel, parseResponse } from "./lib/llm";
|
||||
import { createGrammar, getModel, LlmSession, parseResponse } from "./lib/llm";
|
||||
import {
|
||||
expandReplyTree,
|
||||
getNotes,
|
||||
@@ -118,11 +118,16 @@ async function processPostJob() {
|
||||
|
||||
async function processReplyJob(job: Extract<Job, { type: "reply" }>) {
|
||||
const history: ChatHistoryItem[] = job.history.map((n) => {
|
||||
const type = n.userId === me.id ? ("model" as const) : ("user" as const);
|
||||
if (n.userId === me.id) {
|
||||
return {
|
||||
type: "model",
|
||||
response: [formatNote(n)],
|
||||
} as const;
|
||||
}
|
||||
return {
|
||||
type,
|
||||
type: "user",
|
||||
text: formatNote(n),
|
||||
} as ChatHistoryItem;
|
||||
} as const;
|
||||
});
|
||||
const text = await (async () => {
|
||||
await using session = new LlmSession(model, replyJobPrompt, history);
|
||||
@@ -221,10 +226,6 @@ function initializeStream() {
|
||||
await misskey.request("following/create", { userId: e.id });
|
||||
}
|
||||
});
|
||||
|
||||
channel.on("unfollow", async (e) => {
|
||||
await misskey.request("following/delete", { userId: e.id });
|
||||
});
|
||||
}
|
||||
|
||||
/** pop from the job queue and run it */
|
||||
|
||||
Reference in New Issue
Block a user