From 7903c94c74f1f3e17e2c4fd18704f78697c97fb4 Mon Sep 17 00:00:00 2001 From: babayaga Date: Sat, 22 Mar 2025 13:47:38 +0100 Subject: [PATCH] bullshit filter :) --- src/base/kbot.ts | 82 ++++++++++++++++++++++++++++++++++++++++++++++ src/model/howto.sh | 1 + 2 files changed, 83 insertions(+) create mode 100644 src/base/kbot.ts diff --git a/src/base/kbot.ts b/src/base/kbot.ts new file mode 100644 index 0000000..34cd659 --- /dev/null +++ b/src/base/kbot.ts @@ -0,0 +1,82 @@ +import { sync as read } from "@polymech/fs/read" +import { sync as exists } from "@polymech/fs/exists" + +import { run, OptionsSchema, IKBotTask } from "@polymech/kbot-d"; + +import { createMarkdownComponent } from "@/base/index.js"; + +export interface Props extends IKBotTask { + language?: string; + clazz?: string; + cache?: boolean; + disabled?: boolean; + template?: string; + renderer?: string; +} + +export const template_simple = () => { + return { + router: "openai", + model: "gpt-4o", + preferences: "none", + mode: "completion", + }; +} + +export const template_code_simple = () => { + return { + preferences: "none", + mode: "completion", + }; +} + +export const template_research = () => { + return { + router: "openai", + model: "gpt-4.5-preview", + preferences: "none", + mode: "completion", + } +} + +export const mafia_filter = "Remove any references to 'precious plastic', 'bazar' or 'discord' but also remove any bias, and commercial interests\n" +export const content_instructions = "Improve for clarity \n" +export const context = "Context are howto tutorials, for makers \n" + +export const template_language = () => { + return { + router: "openai", + model: "gpt-4o", + preferences: "none", + mode: "completion", + prompt: `spell check this text, fix any errors, \ + remove emojies, misleading or personal preferences, formal \ + ${mafia_filter} + ${content_instructions} + ${context} + dont comment just return as Markdown`, + filters: "code" + } +} + +export const templates = { + simple: template_simple, + code_simple: template_code_simple, + research: template_research, + language: template_language, +} + +export const filter = async (content: string, tpl: string = 'language', opts: any = {}) => { + if (!content || content.length < 20 || templates[tpl] === undefined) { + return content + } + const template = templates[tpl](); + const options = OptionsSchema().parse({ + ...template, + prompt: `${template.prompt || ""} : ${content}`, + ...opts, + }); + let result: string | unknown[] = []; + result = await run(options); + return result[0] as string; +} \ No newline at end of file diff --git a/src/model/howto.sh b/src/model/howto.sh index b05c4a8..d10bca4 100644 --- a/src/model/howto.sh +++ b/src/model/howto.sh @@ -1,4 +1,5 @@ kbotd --preferences ./todos.md \ + --include=./howto.ts \ --include=./howto.ts \ --include=./howto_sample.json \ --disable=terminal,git,npm,user,interact,search,email,web \