Rework algorithm

This commit is contained in:
2025-10-02 09:52:05 +00:00
parent cc43431a90
commit c276b8e319
6 changed files with 155 additions and 57 deletions

View File

@@ -1,7 +1,6 @@
import { api } from "misskey-js";
import type { Note } from "misskey-js/entities.js";
import { sample } from "./util";
import type { Message } from "./llm";
export const misskey = new api.APIClient({
origin: Bun.env["MISSKEY_ORIGIN"] || "https://misskey.cannorin.net",
@@ -19,7 +18,7 @@ export const isSuitableAsInput = (n: Note) =>
n.text.length > 0;
/** randomly sample some notes from the timeline */
export async function getNotes() {
export async function getNotes(localNotesCount = 5, globalNotesCount = 10) {
// randomly sample N local notes
const localNotes = (count: number) =>
misskey
@@ -34,7 +33,10 @@ export async function getNotes() {
.then((xs) => xs.filter(isSuitableAsInput))
.then((xs) => sample(xs, count));
const notes = await Promise.all([localNotes(5), globalNotes(10)]);
const notes = await Promise.all([
localNotes(localNotesCount),
globalNotes(globalNotesCount),
]);
return sample(notes.flat());
}
@@ -48,9 +50,3 @@ export async function expandReplyTree(
const reply = await misskey.request("notes/show", { noteId: note.reply.id });
return await expandReplyTree(reply, [...acc, note], cutoff - 1);
}
/** convert a note to a chat message */
export const noteToMessage = (note: Note): Message => ({
type: note.userId === me.id ? ("model" as const) : ("user" as const),
text: note.text?.replaceAll(`@${me.username}`, "") || "",
});