generated from polymech/site-template
refactor
This commit is contained in:
parent
facced1b78
commit
d39d0fc1d8
@ -23,7 +23,7 @@
|
||||
"format": "unix-time"
|
||||
}
|
||||
],
|
||||
"default": "2025-03-25T12:11:36.725Z"
|
||||
"default": "2025-03-25T19:32:53.069Z"
|
||||
},
|
||||
"description": {
|
||||
"type": "string",
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -109,7 +109,6 @@ export const templates = {
|
||||
learned_skills: extract_learned_skills,
|
||||
local: local
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param content : content to filter
|
||||
@ -119,61 +118,25 @@ export const templates = {
|
||||
*/
|
||||
export const filter = async (content: string, tpl: string = 'howto', 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;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param content : complete content
|
||||
* @param tpl : kbot template
|
||||
* @param opts
|
||||
* @returns
|
||||
*/
|
||||
export const extract = async (content: string, tpl: string = 'keywords', 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;
|
||||
return content;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Completion
|
||||
/**
|
||||
*
|
||||
* @param content : complete content
|
||||
* @param tpl : kbot template
|
||||
* @param opts
|
||||
* @returns
|
||||
*/
|
||||
export const references = async (content: string, tpl: string = 'references', opts: any = {}) => {
|
||||
if (!content || content.length < 20 || templates[tpl] === undefined) {
|
||||
return content
|
||||
}
|
||||
const template = templates[tpl]();
|
||||
const options = OptionsSchema().parse({
|
||||
|
||||
// 🔸 Separate the options hash
|
||||
const options = getFilterOptions(content, template, opts);
|
||||
|
||||
let result: string | unknown[] = [];
|
||||
result = await run(options);
|
||||
return result[0] as string;
|
||||
};
|
||||
|
||||
// 🔸 Expose this for caching or debugging
|
||||
export const getFilterOptions = (content: string, template: any, opts: any = {}) => {
|
||||
return OptionsSchema().parse({
|
||||
...template,
|
||||
prompt: `${template.prompt || ""} : ${content}`,
|
||||
...opts,
|
||||
});
|
||||
let result: string | unknown[] = [];
|
||||
result = await run(options);
|
||||
return result[0] as string;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -92,8 +92,8 @@ if (HOWTO_ADD_HARDWARE) {
|
||||
}
|
||||
|
||||
if (HOWTO_COMPLETE_RESOURCES) {
|
||||
const keywords = (await extract(contentAll)) as string;
|
||||
const references_extra = await references(keywords);
|
||||
const keywords = (await filter(contentAll,'keywords')) as string;
|
||||
const references_extra = await filter(keywords,'references');
|
||||
howto_resources = `${howto_resources}\n${references_extra}`;
|
||||
}
|
||||
|
||||
|
||||
@ -23,12 +23,12 @@ export const I18N_ASSET_PATH = "${SRC_DIR}/${SRC_NAME}-${DST_LANG}${SRC_EXT}"
|
||||
export const HOWTO_GLOB = '**/config.json'
|
||||
export const FILES_WEB = 'https://files.polymech.io/files/machines/howtos/'
|
||||
export const HOWTO_FILTER_LLM = true
|
||||
export const HOWTO_ANNOTATIONS = true
|
||||
export const HOWTO_ANNOTATIONS = false
|
||||
export const HOWTO_ANNOTATIONS_CACHE = true
|
||||
export const HOWTO_COMPLETE_RESOURCES = true
|
||||
export const HOWTO_ADD_HARDWARE = true
|
||||
export const HOWTO_COMPLETE_SKILLS = true
|
||||
export const HOWTO_LOCAL_RESOURCES = true
|
||||
export const HOWTO_ADD_HARDWARE = false
|
||||
export const HOWTO_COMPLETE_SKILLS = false
|
||||
export const HOWTO_LOCAL_RESOURCES = false
|
||||
|
||||
export const HOWTO_MIGRATION = () => path.resolve(resolve("./data/last.json"))
|
||||
export const HOWTO_ROOT_INTERN = () => path.resolve(resolve("./public/resources/howtos"))
|
||||
|
||||
@ -5,7 +5,7 @@ import { HOWTO_FILTER_LLM, HOWTO_ROOT } from "config/config.js";
|
||||
export const item_path = (item: any) => `${HOWTO_ROOT()}/${item.data.slug}`
|
||||
|
||||
const blacklist_ = [];
|
||||
export const blacklist = ['precious-plastic', 'fair-enough', 'mad-plastic-labs', 'the-flipflopi', 'easymoulds', 'plasticpreneur', 'sustainable-design-studio', 'johannplasto'];
|
||||
export const blacklist = ['precious-plastic', 'fair-enough', 'mad-plastic-labs',, 'easymoulds', 'plasticpreneur', 'sustainable-design-studio', 'johannplasto'];
|
||||
|
||||
export const urlBlacklist = ["thenounproject.com", "preciousplastic.com"];
|
||||
export const bannedWords = ["wizard", "magic2"];
|
||||
|
||||
@ -12,13 +12,10 @@ import type { Loader, LoaderContext } from 'astro/loaders'
|
||||
|
||||
export * from './howto-model.js'
|
||||
export * from './filters.js'
|
||||
|
||||
import { filter as language } from "@/base/kbot.js";
|
||||
import { IHowto, IImage, ITag, ITEM_TYPE } from './howto-model.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 { AnnotationMode, generateCacheKey, cacheAnnotation, getCachedAnnotation } from './annotation.js'
|
||||
import { blacklist } from './filters.js'
|
||||
import { download } from './download.js'
|
||||
import {
|
||||
@ -34,6 +31,8 @@ import {
|
||||
} from "config/config.js";
|
||||
import { logger } from '@/base/index.js'
|
||||
|
||||
import { applyFilters } from './filters.js'
|
||||
|
||||
//export const load = () => get(`${HOWTO_ROOT()}/${HOWTO_GLOB}`, HOWTO_ROOT(), ITEM_TYPE)
|
||||
export const item_path = (item: any) => `${HOWTO_ROOT()}/${item.data.slug}`
|
||||
|
||||
@ -45,7 +44,6 @@ export const asset_local_abs = async (item: IHowto, asset: IImage) => {
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
export const downloadFiles = async (dst: string, howto: IHowto) => {
|
||||
const asset_root = path.join(HOWTO_ROOT(), howto.slug)
|
||||
return await pMap(howto.files, async (i) => {
|
||||
@ -107,7 +105,6 @@ export const asset_local_rel = async (item: IHowto, asset: IImage) => {
|
||||
}
|
||||
return default_image().src
|
||||
}
|
||||
|
||||
export const raw = async () => {
|
||||
const src = HOWTO_MIGRATION()
|
||||
const data = read(src, 'json') as any;
|
||||
@ -149,12 +146,25 @@ export const defaults = async (data: any, cwd: string, root: string) => {
|
||||
return data;
|
||||
}
|
||||
|
||||
const content = async (str: string) => {
|
||||
const ret = await applyFilters(str)
|
||||
return ret;
|
||||
};
|
||||
|
||||
const complete = async (item: IHowto) =>
|
||||
{
|
||||
if(!HOWTO_ANNOTATIONS){
|
||||
return item
|
||||
}
|
||||
|
||||
const stepsWithFilteredMarkdown = await pMap(
|
||||
item.steps,
|
||||
async (step) => ({
|
||||
...step,
|
||||
text: await content(step.text)
|
||||
}),
|
||||
{ concurrency: 1 },
|
||||
);
|
||||
return item
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user