generated from polymech/site-template
prompts : json
This commit is contained in:
parent
aa1d18e70d
commit
b3da60538c
@ -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",
|
||||
|
||||
@ -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;
|
||||
};
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user