Update micUploadRoutes.js via upload script - 2026-09-21 02:31:23

This commit is contained in:
mike 2026-09-21 02:31:32 +08:00
parent 60364e9105
commit 476d0bf256
1 changed files with 18 additions and 3 deletions

View File

@ -36,10 +36,17 @@ Output ONLY the title text itself. No quotes, no markdown, no explanation.`;
const _KW_SYSTEM_PROMPT_TMPL = (coreNoun) => `You write English search keywords for a Made-in-China.com product listing, following the platform's official rules:
- Format: [modifier] + [core noun]. The core noun in EVERY keyword must be "${coreNoun}" (the same core noun used in the product title) — do not switch to a different core noun.
- NEVER include the specific model number / SKU (e.g. "SR1K") in a keyword. Keywords are generic buyer search phrases, not product-specific identifiers — real buyers search "Rack Mount UPS", never "Rack Mount UPS SR1K".
- Return exactly 10 keywords as a JSON array of strings, ordered by importance: the first 3 are the most important/representative and should reflect the product's most defining traits.
- Keywords 4-10 should echo the title's modifiers with light variation (different buyer phrasing/synonyms for the same modifiers), not introduce unrelated product types.
- No duplicate keywords (case/plural-insensitive).
- No duplicate or near-duplicate keywords: treat different spellings/spacing of the same modifier as duplicates too (e.g. "Rack Mount" and "Rackmount" count as the same modifier — only use one form).
- Each keyword: 2-4 words.
Example (official guide's own example, for format reference only):
Title core idea: "Luxury King Size Wooden Frame Headboard Hotel Bed"
Good keywords: "Hotel Bed", "Wooden Frame Headboard Bed", "King Size Bed"
(Notice: no model number, no SKU, no brand-specific text — just modifier + core noun.)
Output ONLY a JSON array of exactly 10 strings, nothing else.`;
// 把 buildAttributeList 生成的属性列表挑几条最有代表性的,拼成一段给AI看的
@ -126,7 +133,10 @@ async function generateKeywords(ctx, title, model, log) {
const messages = [
{ role: 'system', content: _KW_SYSTEM_PROMPT_TMPL(coreNoun) },
{ role: 'user', content: `Product title: ${title}\nModel: ${model}\nGenerate 10 keywords now.` },
{
role: 'user',
content: `Product title: ${title}\n(Model "${model}" is given only for your context — DO NOT put it in any keyword.)\nGenerate 10 keywords now.`,
},
];
try {
const content = await ctx.callDeepSeekWithRetry(apiKey, messages, { temperature: 0.7, maxTokens: 400 }, 2);
@ -137,10 +147,15 @@ async function generateKeywords(ctx, title, model, log) {
}
const parsed = JSON.parse(raw.trim());
if (!Array.isArray(parsed)) throw new Error('AI返回的不是数组');
const modelLower = String(model || '').trim().toLowerCase();
const seen = new Set();
const unique = [];
for (const kw of parsed) {
const s = String(kw).trim();
let s = String(kw).trim();
// 兜底:万一AI还是把型号塞进去了,这里强制去掉(防止prompt没完全管住)
if (modelLower && s.toLowerCase().includes(modelLower)) {
s = s.replace(new RegExp(model.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'ig'), '').replace(/\s+/g, ' ').trim();
}
if (s && !seen.has(s.toLowerCase())) { seen.add(s.toLowerCase()); unique.push(s); }
}
if (unique.length < 10) throw new Error(`只生成了${unique.length}个`);