prompts : json

This commit is contained in:
lovebird 2025-03-26 17:58:41 +01:00
parent aa1d18e70d
commit b3da60538c
2 changed files with 20 additions and 0 deletions

View File

@ -128,6 +128,10 @@ const PromptRegistrySchema = z.record(PromptSchema);
type PromptRegistry = z.infer<typeof PromptRegistrySchema>;
const DEFAULT_PROMPTS: PromptRegistry = {
seo: {
template: "Analyze the following content and return a JSON object with these fields: keywords (array of max 10 strings), title (string), description (string), tags (array of max 5 strings). Format as valid JSON only.",
format: 'json'
},
keywords: {
template: "Return a list of max. 10 keywords that can be used for SEO purposes, separated by commas (dont comment, just the list) : ",
format: 'text'
@ -184,6 +188,11 @@ export const createTemplates = (context: TemplateContext = TemplateContext.COMMO
switch (context) {
case TemplateContext.COMMONS:
return {
seo: createTemplate(config, 'seo', {
router: "openai",
model: "gpt-4o",
...DEFAULT_TEMPLATE_OPTIONS
}, 'seo'),
simple: createTemplate(config, 'simple', {
router: "openai",
model: "gpt-4o",

View File

@ -30,6 +30,17 @@ export const filter = async (content: string, tpl: string = 'howto', opts: Props
const template = typeof templates[tpl] === 'function' ? templates[tpl]() : templates[tpl];
const options = getFilterOptions(content, template, opts);
const result = await run(options);
// Handle JSON format responses
if (template.format === 'json') {
try {
return JSON.parse(result[0] as string);
} catch (e) {
console.error('Failed to parse JSON response:', e);
return result[0];
}
}
return result[0] as string;
};