Tweaks to prompt data format

This commit is contained in:
2025-02-21 12:01:15 -05:00
parent cff176e7a3
commit 694014934c
2 changed files with 13 additions and 15 deletions

View File

@@ -53,7 +53,7 @@ router.get('/debug', async (req, res) => {
console.log('Loading prompt...'); console.log('Loading prompt...');
const currentPrompt = await loadPrompt(pool); const currentPrompt = await loadPrompt(pool);
const sampleData = [{ name: "Sample Product" }]; const sampleData = [{ name: "Sample Product" }];
const fullPrompt = currentPrompt + '\n' + JSON.stringify(sampleData, null, 2); const fullPrompt = currentPrompt + '\n' + JSON.stringify(sampleData);
const response = { const response = {
cacheStatus: { cacheStatus: {
@@ -173,10 +173,9 @@ async function getTaxonomyData(pool) {
.filter(item => item.level_order === level && item.master_cat_id === parentId) .filter(item => item.level_order === level && item.master_cat_id === parentId)
.map(item => { .map(item => {
const children = formatHierarchy(items, level + 1, item.cat_id); const children = formatHierarchy(items, level + 1, item.cat_id);
return { return children.length > 0 ?
name: item.name, [item.cat_id, item.name, children] :
...(children.length > 0 ? { subcategories: children } : {}) [item.cat_id, item.name];
};
}); });
}; };
@@ -187,20 +186,19 @@ async function getTaxonomyData(pool) {
.map(item => { .map(item => {
const subthemes = items const subthemes = items
.filter(subitem => subitem.master_cat_id === item.cat_id) .filter(subitem => subitem.master_cat_id === item.cat_id)
.map(subitem => subitem.name); .map(subitem => [subitem.cat_id, subitem.name]);
return { return subthemes.length > 0 ?
name: item.name, [item.cat_id, item.name, subthemes] :
...(subthemes.length > 0 ? { subthemes } : {}) [item.cat_id, item.name];
};
}); });
}; };
cache.taxonomyData = { cache.taxonomyData = {
categories: formatHierarchy(categories), categories: formatHierarchy(categories),
themes: formatThemes(themes), themes: formatThemes(themes),
colors: colors.map(c => c.name), colors: colors.map(c => [c.color, c.name]),
taxCodes: (taxCodes || []).map(tc => ({ id: tc.tax_code_id, name: tc.name })), taxCodes: (taxCodes || []).map(tc => [tc.tax_code_id, tc.name]),
sizeCategories: (sizeCategories || []).map(sc => ({ id: sc.cat_id, name: sc.name })) sizeCategories: (sizeCategories || []).map(sc => [sc.cat_id, sc.name])
}; };
cache.lastUpdated = Date.now(); cache.lastUpdated = Date.now();
@@ -260,7 +258,7 @@ router.post('/validate', async (req, res) => {
// Load the prompt and append the products data // Load the prompt and append the products data
const basePrompt = await loadPrompt(req.app.locals.pool); const basePrompt = await loadPrompt(req.app.locals.pool);
const fullPrompt = basePrompt + '\n' + JSON.stringify(products, null, 2); const fullPrompt = basePrompt + '\n' + JSON.stringify(products);
console.log('📝 Generated prompt:', fullPrompt); console.log('📝 Generated prompt:', fullPrompt);
console.log('🤖 Sending request to OpenAI...'); console.log('🤖 Sending request to OpenAI...');

View File

@@ -168,7 +168,7 @@ export function AiValidationDebug() {
id="costPerMillion" id="costPerMillion"
type="number" type="number"
className="w-full px-3 py-2 border rounded-md" className="w-full px-3 py-2 border rounded-md"
defaultValue="3" defaultValue="2.50"
onChange={(e) => { onChange={(e) => {
const costPerMillion = parseFloat(e.target.value) const costPerMillion = parseFloat(e.target.value)
if (!isNaN(costPerMillion)) { if (!isNaN(costPerMillion)) {