Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions js/plugins/google-genai/src/common/converters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ function toGeminiMedia(part: Part): GeminiPart {
media.videoMetadata = { ...videoMetadata };
}

// Media resolution
if (part.metadata?.mediaResolution) {
media.mediaResolution = { ...part.metadata.mediaResolution };
}

return maybeAddGeminiThoughtSignature(part, media);
}

Expand Down
11 changes: 11 additions & 0 deletions js/plugins/google-genai/src/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,16 @@ export declare interface VideoMetadata {
fps?: number;
}

export enum MediaResolutionLevel {
MEDIA_RESOUTION_LOW = 'MEDIA_RESOUTION_LOW',
MEDIA_RESOLUTION_MEDIUM = 'MEDIA_RESOLUTION_MEDIUM',
MEDIA_RESOLUTION_HIGH = 'MEDIA_RESOLUTION_HIGH',
}

export declare interface MediaResolution {
level?: MediaResolutionLevel;
}

/**
* This is a Gemini Part. (Users never see this
* structure, it is just built by the converters.)
Expand All @@ -732,6 +742,7 @@ export declare interface Part {
executableCode?: ExecutableCode;
codeExecutionResult?: CodeExecutionResult;
videoMetadata?: VideoMetadata;
mediaResolution?: MediaResolution;
}

/**
Expand Down
8 changes: 8 additions & 0 deletions js/plugins/google-genai/tests/common/converters_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ describe('toGeminiMessage', () => {
contentType: 'image/jpeg',
url: 'data:image/jpeg;base64,SHORTENED_BASE64_DATA',
},
metadata: {
mediaResolution: {
level: 'MEDIA_RESOLUTION_HIGH',
},
},
},
],
},
Expand All @@ -137,6 +142,9 @@ describe('toGeminiMessage', () => {
mimeType: 'image/jpeg',
data: 'SHORTENED_BASE64_DATA',
},
mediaResolution: {
level: 'MEDIA_RESOLUTION_HIGH',
},
},
],
},
Expand Down
22 changes: 22 additions & 0 deletions js/testapps/basic-gemini/src/index-vertexai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,28 @@ ai.defineFlow('reasoning', async (_, { sendChunk }) => {
return message;
});

// Media resolution
ai.defineFlow('gemini-media-resolution', async (_) => {
const plant = fs.readFileSync('palm_tree.png', { encoding: 'base64' });
const { text } = await ai.generate({
model: vertexAI.model('gemini-3-pro-preview'),
prompt: [
{ text: 'What is in this picture?' },
{
media: { url: `data:image/png;base64,${plant}` },
metadata: {
mediaResolution: {
// Or MEDIA_RESOLUTION_LOW Or MEDIA_RESOLUTION_MEDIUM
level: 'MEDIA_RESOLUTION_HIGH',
},
},
},
],
});

return text;
});

// Image editing with Gemini.
ai.defineFlow('gemini-image-editing', async (_) => {
const plant = fs.readFileSync('palm_tree.png', { encoding: 'base64' });
Expand Down
25 changes: 25 additions & 0 deletions js/testapps/basic-gemini/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,31 @@ ai.defineFlow('reasoning', async (_, { sendChunk }) => {
return message;
});

// Media resolution
ai.defineFlow('gemini-media-resolution', async (_) => {
const plant = fs.readFileSync('palm_tree.png', { encoding: 'base64' });
const { text } = await ai.generate({
model: googleAI.model('gemini-3-pro-preview'),
prompt: [
{ text: 'What is in this picture?' },
{
media: { url: `data:image/png;base64,${plant}` },
metadata: {
mediaResolution: {
// Or MEDIA_RESOLUTION_LOW Or MEDIA_RESOLUTION_MEDIUM
level: 'MEDIA_RESOLUTION_HIGH',
},
},
},
],
config: {
// MediaResolution is currently only supported in v1alpha for googleAI
apiVersion: 'v1alpha',
},
});
return text;
});

// Image editing with Gemini.
ai.defineFlow('gemini-image-editing', async (_) => {
const plant = fs.readFileSync('palm_tree.png', { encoding: 'base64' });
Expand Down