fix: 传图修复
This commit is contained in:
1 parent
5d39aa55bd
commit
8ba3a67401
2 files changed
+26
-2
No files matched your search
@@ -47,6 +47,15 @@ export type ParsedBrainyChatSubmitMessage = {
|
||||
iframeContext?: Record<string, unknown>;
|
||||
};
|
||||
|
||||
const IMAGE_PRIORITY_INSTRUCTION = [
|
||||
"<attached_image_priority>",
|
||||
"A screenshot image is attached for this message.",
|
||||
"Use the attached image as the primary source of truth.",
|
||||
"Use page context and text prompt only as supporting context.",
|
||||
"If the image conflicts with page context or text, trust the image.",
|
||||
"</attached_image_priority>",
|
||||
].join("\n");
|
||||
|
||||
function trimToUndefined(value: string | undefined): string | undefined {
|
||||
const trimmed = value?.trim();
|
||||
return trimmed ? trimmed : undefined;
|
||||
@@ -132,10 +141,12 @@ export function buildIframeMessageText({
|
||||
text,
|
||||
prompt,
|
||||
pageContext,
|
||||
hasAttachedImage = false,
|
||||
}: {
|
||||
text?: string;
|
||||
prompt?: string;
|
||||
pageContext?: BrainyPageContext;
|
||||
hasAttachedImage?: boolean;
|
||||
}) {
|
||||
const primaryText = trimToUndefined(text) || trimToUndefined(prompt) || "";
|
||||
const sections: string[] = [];
|
||||
@@ -144,6 +155,10 @@ export function buildIframeMessageText({
|
||||
sections.push(primaryText);
|
||||
}
|
||||
|
||||
if (hasAttachedImage) {
|
||||
sections.push(IMAGE_PRIORITY_INSTRUCTION);
|
||||
}
|
||||
|
||||
const normalizedPrompt = trimToUndefined(prompt);
|
||||
if (normalizedPrompt && normalizedPrompt !== primaryText) {
|
||||
sections.push(
|
||||
@@ -233,8 +248,13 @@ export function parseBrainyChatSubmitMessage(
|
||||
const text = trimToUndefined(data.payload?.text);
|
||||
const prompt = trimToUndefined(data.payload?.prompt);
|
||||
const pageContext = normalizePageContext(data.payload?.pageContext);
|
||||
const submitText = buildIframeMessageText({ text, prompt, pageContext });
|
||||
const files = buildScreenshotFileParts(data.payload?.screenshot);
|
||||
const submitText = buildIframeMessageText({
|
||||
text,
|
||||
prompt,
|
||||
pageContext,
|
||||
hasAttachedImage: files.length > 0,
|
||||
});
|
||||
const requestId = trimToUndefined(data.requestId);
|
||||
|
||||
return {
|
||||
|
||||
Reference in new issue
Block a user