Fix AI Studio image generation params

0677777a74637e9f656d88d3471b88ac858f5798

Cohee <18619528+Cohee1207@users.noreply.github.com>

1 files changed, +7 -10Showing whitespace changes
src/endpoints/google.js+7 -10
@@ -424,11 +424,8 @@ router.post('/generate-image', async (request, response) => {
424 const model = request.body.model || 'imagen-3.0-generate-002';424 const model = request.body.model || 'imagen-3.0-generate-002';
425 const { url, headers, apiName } = await getGoogleApiConfig(request, model, 'predict');425 const { url, headers, apiName } = await getGoogleApiConfig(request, model, 'predict');
426426
427 // block_none for safetySetting is currently not supported.
428 // AI Studio is stricter than Vertex AI.427 // AI Studio is stricter than Vertex AI.
429 const safetySetting = request.body.api === 'vertexai'428 const isVertex = request.body.api === 'vertexai';
430 ? 'block_only_high'
431 : 'block_low_and_above';
432429
433 const requestBody = {430 const requestBody = {
434 instances: [{431 instances: [{
@@ -436,14 +433,14 @@ router.post('/generate-image', async (request, response) => {
436 }],433 }],
437 parameters: {434 parameters: {
438 sampleCount: 1,435 sampleCount: 1,
439 seed: Number(request.body.seed ?? Math.floor(Math.random() * 1000000)),436 seed: isVertex ? Number(request.body.seed ?? Math.floor(Math.random() * 1000000)) : undefined,
440 enhancePrompt: Boolean(request.body.enhance ?? false),437 enhancePrompt: isVertex ? Boolean(request.body.enhance ?? false) : undefined,
441 negativePrompt: request.body.negative_prompt || undefined,438 negativePrompt: isVertex ? (request.body.negative_prompt || undefined) : undefined,
442 aspectRatio: String(request.body.aspect_ratio || '1:1'),439 aspectRatio: String(request.body.aspect_ratio || '1:1'),
443 personGeneration: 'allow_all',440 personGeneration: 'allow_all',
444 language: 'auto',441 language: isVertex ? 'auto' : undefined,
445 safetySetting: safetySetting,442 safetySetting: isVertex ? 'block_only_high' : 'block_low_and_above',
446 addWatermark: false,443 addWatermark: isVertex ? false : undefined,
447 outputOptions: {444 outputOptions: {
448 mimeType: 'image/jpeg',445 mimeType: 'image/jpeg',
449 compressionQuality: 100,446 compressionQuality: 100,