generated from polymech/site-template
howto : resources:)
This commit is contained in:
parent
218c8df7cd
commit
28e3524297
@ -23,7 +23,7 @@
|
||||
"format": "unix-time"
|
||||
}
|
||||
],
|
||||
"default": "2025-03-27T13:59:56.687Z"
|
||||
"default": "2025-03-27T19:36:46.952Z"
|
||||
},
|
||||
"description": {
|
||||
"type": "string",
|
||||
|
||||
File diff suppressed because one or more lines are too long
@ -1,9 +1,9 @@
|
||||
{
|
||||
"model": "gpt-4o",
|
||||
"model": "perplexity/sonar-deep-research",
|
||||
"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, eg: sustainable, circular, recycling ... inflated prospects\nContext: howto tutorials, for makers\nConvert units, from metric to imperial and vice versa (in braces)\ndont comment just return as Markdown\n\nText to process:\nAs with any plastic processing process, the resulting parts have a surplus on the edges that has to be removed.\n\nWhen we take the board out of the sheetpress we must try to have a large space to store them without deforming or bending.\n\nWith this type of boards we have the possibility to manufacture countless products, decorative, furniture and much more."
|
||||
"content": "Extract the required tools, software hardware from the following tutorial. Return as Markdown chapters (H3) with very short bullet points (not bold), with links, max. 5.\n\nText to process:\nCreate an adaptable sorting system. If you have a larger quantity of a certain type of material, simply adjust the dividers to accommodate your needs.\n\n\nUser Location: Lisbon, Portugal\n\nIn this step, you may send the provided files for cutting on a CNC or laser cutting machine. Note that these files are designed for a material thickness of 25 mm (1 inch). If you alter this measurement, ensure the file is adjusted accordingly. We only cut the outline on the machine, but you may also use it for bevels and number engravings.\n\nAfter cutting all the panels, use the files with numbers to laser cut them. Ensure proper alignment as each divider panel is numbered on both sides. Align from the top highest corner for best results.\n\nIn this step, cut the front, bottom, and back panels. Additionally, begin finishing all parts and sanding them for a smooth surface.\n\nAfter sanding all parts, assemble them using screws. Begin by attaching the sides and the bottom, then fit the dividers according to your requirements.\n\nYou can now organize your plastic with greater ease."
|
||||
},
|
||||
{
|
||||
"role": "user",
|
||||
|
||||
@ -18,6 +18,7 @@ export interface TemplateProps extends IKBotTask {
|
||||
disabled?: boolean;
|
||||
template?: string;
|
||||
renderer?: string;
|
||||
|
||||
}
|
||||
|
||||
const TemplateConfigSchema = z.object({
|
||||
@ -196,7 +197,8 @@ export const createTemplates = (context: TemplateContext = TemplateContext.COMMO
|
||||
case TemplateContext.HOWTO:
|
||||
return {
|
||||
keywords: createTemplate(config, 'keywords', {
|
||||
model: "google/gemini-exp-1206:free",
|
||||
router: "openai",
|
||||
model: "gpt-4o",
|
||||
...DEFAULT_TEMPLATE_OPTIONS
|
||||
}, 'keywords'),
|
||||
references: createTemplate(config, 'references', {
|
||||
@ -249,5 +251,10 @@ export const createTemplates = (context: TemplateContext = TemplateContext.COMMO
|
||||
export const templates = createTemplates(TemplateContext.COMMONS);
|
||||
|
||||
// Export types
|
||||
export type { TemplateConfig, LLMConfig, Prompt, PromptRegistry };
|
||||
export { InstructionSchema, InstructionSetSchema, TemplateConfigSchema, LLMConfigSchema, PromptSchema, PromptRegistrySchema };
|
||||
export type { TemplateConfig, LLMConfig, Prompt, PromptRegistry }
|
||||
export { InstructionSchema,
|
||||
InstructionSetSchema,
|
||||
TemplateConfigSchema,
|
||||
LLMConfigSchema,
|
||||
PromptSchema,
|
||||
PromptRegistrySchema };
|
||||
@ -41,12 +41,20 @@ export const filter = async (content: string, tpl: string = 'howto', opts: Props
|
||||
tools: []
|
||||
};
|
||||
const ca_options = JSON.parse(JSON.stringify(removeEmpty(cache_key_obj)));
|
||||
const cached = await get_cached_object({ ca_options }, 'kbot');
|
||||
let cached = null
|
||||
try {
|
||||
cached = await get_cached_object({ ca_options }, 'kbot');
|
||||
} catch (e) {
|
||||
logger.error(`Failed to get cached object for ${content.substring(0, 20)}`, e);
|
||||
}
|
||||
if (cached) {
|
||||
logger.debug(`Cache hit for : ${content.substring(0, 20)}`)
|
||||
return cached;
|
||||
}
|
||||
const result = await run(options);
|
||||
if(!result || !result[0]){
|
||||
logger.error(`No result for ${content.substring(0, 20)}`)
|
||||
return content;
|
||||
}
|
||||
if (template.format === 'json') {
|
||||
try {
|
||||
const jsonResult = JSON.parse(result[0] as string);
|
||||
@ -76,12 +84,13 @@ export const template_filter = async (text: string, template: string, context: T
|
||||
])
|
||||
);
|
||||
const resolvedText = resolveVariables(text, true);
|
||||
return await filter(resolvedText, template, {
|
||||
const ret = await filter(resolvedText, template, {
|
||||
context,
|
||||
...resolvedTemplate,
|
||||
prompt: `${resolvedTemplate.prompt}\n\nText to process:\n${resolvedText}`,
|
||||
variables: environment.variables
|
||||
});
|
||||
return ret;
|
||||
};
|
||||
|
||||
export const getFilterOptions = (content: string, template: any, opts: Props = {}) => {
|
||||
|
||||
@ -38,20 +38,9 @@ model_files = model_files.map((f) =>
|
||||
forward_slash(`${howto.slug}/${path.relative(path.resolve(howto_abs), f)}`),
|
||||
);
|
||||
|
||||
const content = async (str: string) => {
|
||||
const ret = await translate(
|
||||
await applyFilters(str),
|
||||
I18N_SOURCE_LANGUAGE,
|
||||
Astro.currentLocale,
|
||||
);
|
||||
return ret;
|
||||
};
|
||||
|
||||
const component = async (str: string) =>
|
||||
await createMarkdownComponent(await content(str));
|
||||
|
||||
const componentHTML = async (str: string) =>
|
||||
await createHTMLComponent(await content(str));
|
||||
const content = async (str: string) => await translate(str,I18N_SOURCE_LANGUAGE, Astro.currentLocale)
|
||||
const component = async (str: string) => await createMarkdownComponent(await content(str));
|
||||
const componentHTML = async (str: string) => await createHTMLComponent(await content(str));
|
||||
|
||||
const stepsWithFilteredMarkdown = await pMap(
|
||||
howto.steps,
|
||||
@ -71,7 +60,6 @@ const authorGeo = howto?.user?.geo || {
|
||||
const authorLinks = (howto?.user?.data.urls || []).filter(
|
||||
(l) => !l.url.includes("one_army") && !l.url.includes("bazar"),
|
||||
);
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Resources
|
||||
@ -84,24 +72,21 @@ 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_ADD_HARDWARE) {
|
||||
const references_extra = await filter(contentAll,'tools_and_hardware')
|
||||
howto_resources = `${howto_resources}\n\n ${references_extra}`
|
||||
}
|
||||
|
||||
const contentAll = `${howto.content}`;
|
||||
if (HOWTO_COMPLETE_RESOURCES) {
|
||||
const keywords = (await filter(contentAll,'keywords')) as string;
|
||||
const references_extra = await filter(keywords,'references');
|
||||
howto_resources = `${howto_resources}\n${references_extra}`;
|
||||
}
|
||||
|
||||
if (HOWTO_ADD_HARDWARE) {
|
||||
const references_extra = await filter(contentAll,'tools_and_hardware')
|
||||
howto_resources = `${howto_resources}\n\n ${references_extra}`
|
||||
}
|
||||
if (HOWTO_COMPLETE_SKILLS) {
|
||||
const references_extra = await filter(contentAll,'learned_skills')
|
||||
howto_resources = `${howto_resources}\n\n ${references_extra}`
|
||||
}
|
||||
|
||||
if (HOWTO_LOCAL_RESOURCES && howto.user && howto.user.geo) {
|
||||
const references_extra = await filter(`Location: ${authorGeo.countryName}`,'local')
|
||||
howto_resources = `${howto_resources}\n\n ${references_extra}`
|
||||
|
||||
@ -25,7 +25,7 @@ export const FILES_WEB = 'https://files.polymech.io/files/machines/howtos/'
|
||||
export const HOWTO_FILTER_LLM = true
|
||||
export const HOWTO_ANNOTATIONS = false
|
||||
export const HOWTO_ANNOTATIONS_CACHE = false
|
||||
export const HOWTO_COMPLETE_RESOURCES = false
|
||||
export const HOWTO_COMPLETE_RESOURCES = true
|
||||
export const HOWTO_ADD_HARDWARE = false
|
||||
export const HOWTO_COMPLETE_SKILLS = false
|
||||
export const HOWTO_LOCAL_RESOURCES = false
|
||||
|
||||
@ -1,22 +1,20 @@
|
||||
{
|
||||
"templates": {
|
||||
"keywords": {
|
||||
"_router": "openai",
|
||||
"model": "google/gemini-exp-1206:free",
|
||||
"router": "openai",
|
||||
"model": "gpt-4o",
|
||||
"preferences": "none",
|
||||
"mode": "completion",
|
||||
"prompt": "Return a list of max. 10 keywords that can be used for SEO purposes, separated by commas (dont comment, just the list) : "
|
||||
},
|
||||
"references": {
|
||||
"_router": "openai",
|
||||
"model": "google/gemini-exp-1206:free",
|
||||
"model": "perplexity/sonar-deep-research",
|
||||
"preferences": "none",
|
||||
"mode": "completion",
|
||||
"prompt": "Return a list of useful references (only with links), as Markdown, grouped : Articles, Books, Papers, Youtube, Opensource Designs, ... Dont comment !",
|
||||
"filters": "code"
|
||||
},
|
||||
"toolsAndHardware": {
|
||||
"router_": "openai",
|
||||
"model": "perplexity/sonar-deep-research",
|
||||
"preferences": "none",
|
||||
"mode": "completion",
|
||||
|
||||
@ -123,4 +123,10 @@ export interface IHowto {
|
||||
version?: string
|
||||
// Added content field (description + steps)
|
||||
content?: string
|
||||
// Added content field : keywords
|
||||
keywords?: string
|
||||
// Added content field : skills
|
||||
skills?: string
|
||||
// Added content field : resources
|
||||
resources?: string
|
||||
}
|
||||
@ -27,12 +27,16 @@ import {
|
||||
HOWTO_FILES_WEB,
|
||||
HOWTO_FILES_ABS,
|
||||
HOWTO_FILTER_LLM,
|
||||
HOWTO_COMPLETE_RESOURCES,
|
||||
|
||||
default_image,
|
||||
HOWTO_ROOT,
|
||||
HOWTO_GLOB,
|
||||
HOWTO_MIGRATION,
|
||||
HOWTO_ANNOTATIONS
|
||||
HOWTO_ANNOTATIONS,
|
||||
HOWTO_COMPLETE_RESOURCES,
|
||||
HOWTO_ADD_HARDWARE,
|
||||
HOWTO_COMPLETE_SKILLS,
|
||||
HOWTO_LOCAL_RESOURCES
|
||||
} from "config/config.js"
|
||||
|
||||
import { env, logger } from '@/base/index.js'
|
||||
@ -99,6 +103,7 @@ export const downloadFiles = async (dst: string, howto: IHowto) => {
|
||||
}
|
||||
}, { concurrency: 1 })
|
||||
}
|
||||
|
||||
export const asset_local_rel = async (item: IHowto, asset: IImage) => {
|
||||
const sanitizedFilename = sanitizeFilename(asset.name).toLowerCase()
|
||||
const asset_path = path.join(HOWTO_ROOT(), item.slug, sanitizedFilename)
|
||||
@ -109,6 +114,7 @@ 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;
|
||||
@ -167,6 +173,7 @@ const to_github = async (item: IHowto) => {
|
||||
`category: ${item.category?.label || 'uncategorized'}`,
|
||||
`difficulty: ${item.difficulty_level}`,
|
||||
`time: ${item.time}`,
|
||||
`keywords: ${item.keywords || ''}`,
|
||||
`location: ${item.user?.geo ? `${item.user.geo.city ? `${item.user.geo.city}, ` : ''}${item.user.geo.countryName || ''}` : ''}`,
|
||||
'---',
|
||||
'',
|
||||
@ -316,6 +323,12 @@ const complete = async (item: IHowto) => {
|
||||
...item.steps.map(step => step.text)
|
||||
].filter(Boolean).join('\n\n')
|
||||
|
||||
// Generate keywords using the keywords template
|
||||
if(HOWTO_COMPLETE_RESOURCES){
|
||||
item.keywords = await template_filter(item.content, 'keywords', TemplateContext.HOWTO);
|
||||
item.resources = await template_filter(item.content, 'toolsAndHardware', TemplateContext.HOWTO);
|
||||
}
|
||||
|
||||
await to_github(item)
|
||||
await to_mdx(item)
|
||||
await to_astro(item)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user