mirror of
https://github.com/JimLiu/baoyu-skills.git
synced 2026-07-12 05:51:44 +08:00
Merge pull request #187 from jiji262/fix/gemini3-image-extraction
fix(gemini-web): recover generated images on Gemini 3
This commit is contained in:
@@ -456,19 +456,19 @@ export class GeminiClient extends GemMixin {
|
|||||||
const generated_images: GeneratedImage[] = [];
|
const generated_images: GeneratedImage[] = [];
|
||||||
const wants_generated =
|
const wants_generated =
|
||||||
get_nested_value(candidate, [12, 7, 0], null) != null ||
|
get_nested_value(candidate, [12, 7, 0], null) != null ||
|
||||||
/http:\/\/googleusercontent\.com\/image_generation_content\/\d+/.test(text);
|
/http:\/\/googleusercontent\.com\/image_generation_content\/\d+/.test(text) ||
|
||||||
|
// Gemini 3 no longer emits the legacy marker in the candidate text; the generated
|
||||||
|
// image arrives in a later response part. Detect it from the raw response instead.
|
||||||
|
/\/gg-dl\//.test(txt) ||
|
||||||
|
/image_generation_content\/\d+/.test(txt);
|
||||||
|
|
||||||
if (wants_generated) {
|
if (wants_generated) {
|
||||||
const image_part = find_generated_image_part(response_json as unknown[], body_index, candidate_index, 1);
|
const image_part = find_generated_image_part(response_json as unknown[], body_index, candidate_index, 1);
|
||||||
const img_body = image_part?.body ?? null;
|
const img_body = image_part?.body ?? null;
|
||||||
|
|
||||||
if (!img_body) {
|
// Not every candidate carries a generated image (e.g. multi-candidate responses).
|
||||||
throw new ImageGenerationError(
|
// If this candidate has no image part, skip extraction instead of failing the whole call.
|
||||||
'Failed to parse generated images. Please update gemini_webapi to the latest version. If the error persists and is caused by the package, please report it on GitHub.',
|
const img_candidate = img_body ? get_nested_value<unknown[]>(img_body, [4, candidate_index], []) : [];
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const img_candidate = get_nested_value<unknown[]>(img_body, [4, candidate_index], []);
|
|
||||||
const finished = get_nested_value<string | null>(img_candidate, [1, 0], null);
|
const finished = get_nested_value<string | null>(img_candidate, [1, 0], null);
|
||||||
if (finished) {
|
if (finished) {
|
||||||
text = finished.replace(/http:\/\/googleusercontent\.com\/image_generation_content\/\d+/g, '').trimEnd();
|
text = finished.replace(/http:\/\/googleusercontent\.com\/image_generation_content\/\d+/g, '').trimEnd();
|
||||||
|
|||||||
Reference in New Issue
Block a user