对生图优化提示词补充原始需求避免偏差

This commit is contained in:
Your Name 2026-02-09 11:39:55 +08:00
parent 419712f1bf
commit dcd5853808

View File

@ -146,7 +146,17 @@ function applyOptimizedPromptToLatestUserMessage(
const textPart = msg.parts.find( const textPart = msg.parts.find(
(part): part is { type: "text"; text: string } => part.type === "text", (part): part is { type: "text"; text: string } => part.type === "text",
); );
const finalPrompt = `${hiddenPromptPrefix}${prompt}`.trim(); const originalText = textPart?.text?.trim() || "";
const normalizedOriginal = hiddenPromptPrefix && originalText.startsWith(hiddenPromptPrefix)
? originalText.slice(hiddenPromptPrefix.length).trim()
: originalText;
const shouldAppendOriginal =
normalizedOriginal &&
normalizedOriginal !== prompt &&
!prompt.includes(normalizedOriginal);
const finalPrompt = shouldAppendOriginal
? `${hiddenPromptPrefix}${prompt}\n\n用户原始需求:${normalizedOriginal}`.trim()
: `${hiddenPromptPrefix}${prompt}`.trim();
if (textPart) { if (textPart) {
textPart.text = finalPrompt; textPart.text = finalPrompt;