mirror of
https://github.com/Dasemu/chatgpt-imagegen-mcp.git
synced 2026-11-26 15:26:21 +00:00
Merge pull request 'fix: never return the reference image as the generated result' (#1) from claude/reference-image-result-bug-2e2179 into main
Reviewed-on: Zenvairo/chatgpt-unofficial-imagegen-mcp#1
This commit is contained in:
commit
9d54c4e1d8
2 files changed
+10
-1
No files matched your search
@@ -10,3 +10,4 @@ Recurring mistakes and how to avoid them. Several of these come from ZenvairoPro
|
||||
- **One process per profile.** Chromium locks the profile directory. Stop the service before `npm run login`.
|
||||
- **Don't force contradictory format rules.** Prospect rejected good images because a prompt rule and a QA aspect-ratio rule disagreed. Aspect ratio is a best-effort hint here and is not validated.
|
||||
- **zsh and `git show rev:path`.** Quote the argument (`git show 'abc^:path'`), or zsh modifiers such as `:r` mangle it.
|
||||
- **Take the image baseline after attaching references.** Reference thumbnails show up in the composer before sending and are not inside a user message, so a baseline taken earlier lets them pass as the generated result. The provider also rejects a download byte-identical to a reference.
|
||||
@@ -1,3 +1,4 @@
|
||||
import { createHash } from "node:crypto";
|
||||
import { cp, mkdtemp } from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
@@ -16,6 +17,8 @@ import { buildImageRequest } from "./prompts.js";
|
||||
|
||||
export const MIN_IMAGE_BYTES = 20_000;
|
||||
|
||||
const sha256 = (data: Buffer): string => createHash("sha256").update(data).digest("hex");
|
||||
|
||||
export interface ImageProvider {
|
||||
generateImages(generationId: string, request: ImageRequest): Promise<StoredOutput[]>;
|
||||
checkSession(): Promise<boolean>;
|
||||
@@ -98,8 +101,9 @@ export class ChatGptImageProvider implements ImageProvider {
|
||||
|
||||
private async generateOne(page: Page, request: ImageRequest): Promise<Buffer> {
|
||||
await openNewChat(page, this.config.url, this.diagnostics);
|
||||
const baseline = await imageSources(page);
|
||||
await attachReferences(page, request.references, this.diagnostics);
|
||||
// Taken after the upload so the reference thumbnails in the composer are never mistaken for the result.
|
||||
const baseline = await imageSources(page);
|
||||
await sendMessage(page, buildImageRequest(request.prompt, request.aspectRatio, request.references.length), this.diagnostics);
|
||||
try {
|
||||
await waitForTurnComplete(page, this.config.turnTimeoutMs, this.diagnostics);
|
||||
@@ -109,6 +113,10 @@ export class ChatGptImageProvider implements ImageProvider {
|
||||
}
|
||||
const src = await waitForGeneratedImage(page, baseline, this.config.imageTimeoutMs, this.diagnostics);
|
||||
const image = await downloadImage(page, src);
|
||||
const digest = sha256(image);
|
||||
if (request.references.some((reference) => sha256(Buffer.from(reference.base64, "base64")) === digest)) {
|
||||
throw new ImageGenerationError("ChatGPT returned the reference image instead of a generated one");
|
||||
}
|
||||
if (image.length < MIN_IMAGE_BYTES) throw new ImageGenerationError(`Downloaded image is suspiciously small (${image.length} bytes)`);
|
||||
if (!imageDimensions(image)) throw new ImageGenerationError("Downloaded file is not a readable PNG, JPEG or WebP image");
|
||||
return image;
|
||||
|
||||
Reference in new issue
Block a user