feat(F-099): completed feature
This commit is contained in:
@@ -266,7 +266,7 @@ export async function registerCatalogRoutes(
|
||||
|
||||
const settingsResult = await deps.pool.query<{ key: string; value: string }>(
|
||||
`SELECT key, value FROM store_settings WHERE key = ANY($1::text[])`,
|
||||
[['ai_base_url', 'ai_model', 'ai_api_key', 'ai_seo_title_prompt', 'ai_seo_description_prompt']],
|
||||
[['ai_base_url', 'ai_model', 'ai_api_key', 'ai_seo_title_prompt', 'ai_seo_description_prompt', 'ai_product_description_prompt']],
|
||||
);
|
||||
const settings = Object.fromEntries(settingsResult.rows.map((row) => [row.key, row.value]));
|
||||
const baseUrl = settings.ai_base_url?.trim();
|
||||
@@ -283,7 +283,10 @@ export async function registerCatalogRoutes(
|
||||
};
|
||||
const promptFor = (template: string | undefined, fallback: string) =>
|
||||
(template || fallback).replace(/\{\{(name|description|brand)\}\}/g, (_, key: string) => replacements[key] ?? '');
|
||||
const patch: { seoTitle?: string; seoDescription?: string } = {};
|
||||
const patch: { description?: string; seoTitle?: string; seoDescription?: string } = {};
|
||||
if (!product.description?.trim()) {
|
||||
patch.description = (await generateWithModel(baseUrl, model, apiKey, promptFor(settings.ai_product_description_prompt, 'Escribe una descripción comercial clara y útil en español para este producto: {{name}}. Devuelve solo la descripción.'))).slice(0, 2_000);
|
||||
}
|
||||
if (!product.seoTitle?.trim()) {
|
||||
patch.seoTitle = (await generateWithModel(baseUrl, model, apiKey, promptFor(settings.ai_seo_title_prompt, 'Genera un título SEO breve para {{name}}. Devuelve solo el título.'))).slice(0, 200);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user