From 167948de72803d7b8446a108389b6cf6bed742b6 Mon Sep 17 00:00:00 2001 From: babayaga Date: Mon, 24 Mar 2025 21:18:11 +0100 Subject: [PATCH] kbot addons : von nuescht wuerd nuescht :) --- .kbot/params.json | 2 +- src/base/kbot.ts | 4 +++- src/components/howtos/Detail2.astro | 15 +++++++++++++-- src/config/config.ts | 1 + src/model/download.ts | 10 ++++++++++ src/model/howto.ts | 16 +++++++++++++++- 6 files changed, 43 insertions(+), 5 deletions(-) diff --git a/.kbot/params.json b/.kbot/params.json index c33ec88..379778c 100644 --- a/.kbot/params.json +++ b/.kbot/params.json @@ -3,7 +3,7 @@ "messages": [ { "role": "user", - "content": "use a formal tone\nspell check the text, fix any errors\nremove emojis\nremove personal preferences or biases\nshorten text if possible but preserve personality\nremove references to preciousplastic, bazar and Discord\nremove any brain/green washing as well suggestions not related to the craft\nContext: howto tutorials, for makers\nConvert units, from metric to imperial and vice versa (in braces)\ndont comment just return as Markdown : Here you will find the 3D model and blueprints to create the wall peg mold!" + "content": "use a formal tone\nspell check the text, fix any errors\nremove emojis\nremove personal preferences or biases\nshorten text if possible but preserve personality\nremove references to preciousplastic, bazar and Discord\nremove any brain/green washing as well suggestions not related to the craft\nContext: howto tutorials, for makers\nConvert units, from metric to imperial and vice versa (in braces)\ndont comment just return as Markdown : # Resources\n\n ### Skills Developed or Improved\n\n- **Recycling and Waste Management**: Understanding the process of collecting, sorting, and processing marine litter and fishing nets for reuse.\n \n- **Material Science and Engineering**: Learning about the properties of polypropylene and how to combine it with recycled materials for optimal texture and color.\n\n- **Manufacturing Process Operation**: Gaining hands-on experience with industrial equipment such as an industrial dryer and modified sheetpress for board production.\n\n- **Prototyping and Product Design**: Developing the ability to design and produce functional and decorative products from recycled materials.\n\n- **Project Management**: Collaborating with different entities (Vertidos Cero Association and AIMPLAS) and managing resources efficiently to support a circular economy initiative." }, { "role": "user", diff --git a/src/base/kbot.ts b/src/base/kbot.ts index e433bd9..f7fb268 100644 --- a/src/base/kbot.ts +++ b/src/base/kbot.ts @@ -82,10 +82,11 @@ export const extract_learned_skills = () => { model: "gpt-4o", preferences: "none", mode: "completion", - prompt: "Analyze the following tutorial and identify all the skills that a person would learn or improve by completing this project. Return as JSON with this structure:\n\n{\n \"gainedSkills\": [\n {\n \"name\": \"Skill name\",\n \"category\": \"Technical, Design, Manual, etc.\",\n \"description\": \"Brief description of how this skill is developed\"\n }\n ],\n \"learningOutcomes\": [\n \"Broader outcomes or knowledge gained from completing the project\"\n ],\n \"possibleExtensions\": [\n \"How this project could be extended to learn more advanced skills\"\n ]\n}\n\nReturn only the JSON. No introductions or explanations.", + prompt: "Analyze the following tutorial and identify all the skills that a person would learn or improve by completing this project. No introductions or explanations. Return as Markdown chapter with a bullet list, max. 5.", filters: "code" }; } + export const templates = { simple: template_simple, code_simple: template_code_simple, @@ -97,6 +98,7 @@ export const templates = { required_skills: extract_required_skills, learned_skills: extract_learned_skills } + /** * * @param content : content to filter diff --git a/src/components/howtos/Detail2.astro b/src/components/howtos/Detail2.astro index 9a8e6fc..4345540 100644 --- a/src/components/howtos/Detail2.astro +++ b/src/components/howtos/Detail2.astro @@ -15,13 +15,15 @@ import { sync as read } from "@polymech/fs/read"; import { createHTMLComponent, createMarkdownComponent } from "@/base/index.js"; import { translate } from "@/base/i18n.js"; import { applyFilters, shortenUrl } from "@/model/howto.js"; -import { extract, references } from "@/base/kbot.js"; +import { extract, extract_learned_skills, references } from "@/base/kbot.js"; import { HOWTO_FILES_WEB, HOWTO_FILES_ABS, I18N_SOURCE_LANGUAGE, HOWTO_COMPLETE_RESOURCES, + HOWTO_COMPLETE_SKILLS } from "config/config.js"; +import { filter } from "@/base/kbot.js"; interface Props { howto: IHowto; @@ -80,13 +82,22 @@ let howto_resources = exists(howto_resources_path) ? read(howto_resources_path, "string") || howto_resources_default : howto_resources_default; +const contentAll = `${howto.title} \n Description : ${howto.description} \n Steps: ${howto.steps.map((s) => s.text).join("\n")} \n`; + if (HOWTO_COMPLETE_RESOURCES) { - const contentAll = `${howto.title} \n Description : ${howto.description} \n Steps: ${howto.steps.map((s) => s.text).join("\n")} \n`; const keywords = (await extract(contentAll)) as string; const references_extra = await references(keywords); howto_resources = `${howto_resources}\n${references_extra}`; } + +if (HOWTO_COMPLETE_SKILLS) { + const references_extra = await filter(contentAll,'learned_skills') + howto_resources = `${howto_resources}\n\n ${references_extra}` +} + const Resources = component(howto_resources); + + --- diff --git a/src/config/config.ts b/src/config/config.ts index 2cb1585..db82305 100644 --- a/src/config/config.ts +++ b/src/config/config.ts @@ -26,6 +26,7 @@ export const HOWTO_FILTER_LLM = true export const HOWTO_ANNOTATIONS = true export const HOWTO_ANNOTATIONS_CACHE = true export const HOWTO_COMPLETE_RESOURCES = false +export const HOWTO_COMPLETE_SKILLS = true export const HOWTO_MIGRATION = () => path.resolve(resolve("./data/last.json")) export const HOWTO_ROOT_INTERN = () => path.resolve(resolve("./public/resources/howtos")) diff --git a/src/model/download.ts b/src/model/download.ts index e69de29..a97c5da 100644 --- a/src/model/download.ts +++ b/src/model/download.ts @@ -0,0 +1,10 @@ +import { got } from 'got' +import { createWriteStream } from 'fs'; +export const download = async (url, outputPath) => { + const stream = createWriteStream(outputPath); + got.stream(url).pipe(stream); + return new Promise((resolve, reject) => { + stream.on('finish', () => resolve(`File downloaded: ${outputPath}`)); + stream.on('error', reject); + }); + } \ No newline at end of file diff --git a/src/model/howto.ts b/src/model/howto.ts index 3db036a..0cc991f 100644 --- a/src/model/howto.ts +++ b/src/model/howto.ts @@ -16,6 +16,9 @@ export * from './filters.js' import { filter as language } from "@/base/kbot.js"; import { IHowto, IImage, ITag, ITEM_TYPE } from './howto-model.js'; import type { IAnnotation } from "./annotation.js" + +import { AnnotationMode, generateCacheKey, cacheAnnotation, getCachedAnnotation } from './annotation.js'; + import { blacklist } from './filters.js' import { download } from './download.js' import { @@ -26,7 +29,8 @@ import { default_image, HOWTO_ROOT, HOWTO_GLOB, - HOWTO_MIGRATION + HOWTO_MIGRATION, + HOWTO_ANNOTATIONS } from "config/config.js"; import { logger } from '@/base/index.js' @@ -145,6 +149,15 @@ export const defaults = async (data: any, cwd: string, root: string) => { return data; } +const complete = async (item: IHowto) => +{ + if(!HOWTO_ANNOTATIONS){ + return item + } + + return item +} + const onStoreItem = async (store: any, ctx: LoaderContext) => { const item = store.data.item as IHowto item.steps = item.steps || [] @@ -165,6 +178,7 @@ const onStoreItem = async (store: any, ctx: LoaderContext) => { step.images = step.images.filter((image) => asset_local_abs(item, image)) }) item.files = await downloadFiles(item.slug, item) + await complete(item) return item }