diff options
Diffstat (limited to 'tools/compare-models/src/bookmarkProcessor.ts')
| -rw-r--r-- | tools/compare-models/src/bookmarkProcessor.ts | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/tools/compare-models/src/bookmarkProcessor.ts b/tools/compare-models/src/bookmarkProcessor.ts new file mode 100644 index 00000000..4a1bbf0a --- /dev/null +++ b/tools/compare-models/src/bookmarkProcessor.ts @@ -0,0 +1,68 @@ +import type { InferenceClient } from "@karakeep/shared/inference"; +import { buildTextPrompt } from "@karakeep/shared/prompts.server"; + +import { inferTags } from "./inferenceClient"; +import type { Bookmark } from "./types"; + +export async function extractBookmarkContent( + bookmark: Bookmark, +): Promise<string> { + if (bookmark.content.type === "link") { + const parts = []; + + if (bookmark.content.url) { + parts.push(`URL: ${bookmark.content.url}`); + } + + if (bookmark.title) { + parts.push(`Title: ${bookmark.title}`); + } + + if (bookmark.content.description) { + parts.push(`Description: ${bookmark.content.description}`); + } + + if (bookmark.content.htmlContent) { + parts.push(`Content: ${bookmark.content.htmlContent}`); + } + + return parts.join("\n"); + } + + if (bookmark.content.type === "text" && bookmark.content.text) { + return bookmark.content.text; + } + + return ""; +} + +export async function runTaggingForModel( + bookmark: Bookmark, + inferenceClient: InferenceClient, + lang: string = "english", + contextLength: number = 8000, +): Promise<string[]> { + const content = await extractBookmarkContent(bookmark); + + if (!content) { + return []; + } + + try { + // Use the shared prompt builder with empty custom prompts and default tag style + const prompt = await buildTextPrompt( + lang, + [], // No custom prompts for comparison tool + content, + contextLength, + "as-generated", // Use tags as generated by the model + ); + + const tags = await inferTags(inferenceClient, prompt); + return tags; + } catch (error) { + throw new Error( + `Failed to generate tags: ${error instanceof Error ? error.message : String(error)}`, + ); + } +} |
