From c0c8c1ccbead45e974aecd0fbe143cc2f1e2a3cf Mon Sep 17 00:00:00 2001 From: zezutom Date: Tue, 28 May 2024 22:54:37 +0200 Subject: [PATCH 1/2] feat(firestore-multimodal-genai) added support for response_mime_type --- firestore-genai-chatbot/extension.yaml | 16 ++++++++++++++++ .../functions/package.json | 2 +- .../functions/src/config.ts | 1 + .../src/generative-client/generative_ai.ts | 1 + 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/firestore-genai-chatbot/extension.yaml b/firestore-genai-chatbot/extension.yaml index 99162420..9937cf51 100644 --- a/firestore-genai-chatbot/extension.yaml +++ b/firestore-genai-chatbot/extension.yaml @@ -258,6 +258,22 @@ params: required: false immutable: false + - param: RESPONSE_MIME_TYPE + label: Output response mimetype of the generated candidate text. + description: >- + Supported mimetype: + - text/plain: (default) Text output. + - application/json: JSON response in the candidates. + The model needs to be prompted to output the appropriate response type, otherwise the behavior is undefined. + type: select + options: + - label: JSON + value: application/json + - label: Text + value: text/plain + default: text/plain + required: false + - param: CANDIDATE_COUNT label: Candidate count description: >- diff --git a/firestore-multimodal-genai/functions/package.json b/firestore-multimodal-genai/functions/package.json index 483c6312..01a5d7f0 100644 --- a/firestore-multimodal-genai/functions/package.json +++ b/firestore-multimodal-genai/functions/package.json @@ -14,7 +14,7 @@ "@google-ai/generativelanguage": "^2.3.0", "@google-cloud/aiplatform": "^3.19.0", "@google-cloud/vertexai": "^1.1.0", - "@google/generative-ai": "^0.8.0", + "@google/generative-ai": "^0.11.4", "@types/jest": "^29.5.12", "@types/mustache": "^4.2.2", "firebase-admin": "^12.1.0", diff --git a/firestore-multimodal-genai/functions/src/config.ts b/firestore-multimodal-genai/functions/src/config.ts index 74e0685d..cd15d8b6 100644 --- a/firestore-multimodal-genai/functions/src/config.ts +++ b/firestore-multimodal-genai/functions/src/config.ts @@ -126,4 +126,5 @@ export default { safetySettings: getSafetySettings(), bucketName: process.env.BUCKET_NAME || defaultBucketName, imageField: process.env.IMAGE_FIELD, + responseMimeType: process.env.RESPONSE_MIME_TYPE || 'text/plain', }; diff --git a/firestore-multimodal-genai/functions/src/generative-client/generative_ai.ts b/firestore-multimodal-genai/functions/src/generative-client/generative_ai.ts index ed7e30d4..90c8a776 100644 --- a/firestore-multimodal-genai/functions/src/generative-client/generative_ai.ts +++ b/firestore-multimodal-genai/functions/src/generative-client/generative_ai.ts @@ -66,6 +66,7 @@ export class GeminiGenerativeClient extends GenerativeClient< temperature: options.temperature, candidateCount: options.candidateCount, maxOutputTokens: options.maxOutputTokens, + responseMimeType: config.responseMimeType, }, safetySettings: options.safetySettings, }); From 03ec571906a94e7c5f1ce3d20557cb176de5d1cf Mon Sep 17 00:00:00 2001 From: zezutom Date: Wed, 29 May 2024 13:41:10 +0200 Subject: [PATCH 2/2] Moved the config update to the correct place. --- firestore-genai-chatbot/extension.yaml | 16 ---------------- firestore-multimodal-genai/extension.yaml | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/firestore-genai-chatbot/extension.yaml b/firestore-genai-chatbot/extension.yaml index 9937cf51..99162420 100644 --- a/firestore-genai-chatbot/extension.yaml +++ b/firestore-genai-chatbot/extension.yaml @@ -258,22 +258,6 @@ params: required: false immutable: false - - param: RESPONSE_MIME_TYPE - label: Output response mimetype of the generated candidate text. - description: >- - Supported mimetype: - - text/plain: (default) Text output. - - application/json: JSON response in the candidates. - The model needs to be prompted to output the appropriate response type, otherwise the behavior is undefined. - type: select - options: - - label: JSON - value: application/json - - label: Text - value: text/plain - default: text/plain - required: false - - param: CANDIDATE_COUNT label: Candidate count description: >- diff --git a/firestore-multimodal-genai/extension.yaml b/firestore-multimodal-genai/extension.yaml index 3b855b21..9c2fbeb8 100644 --- a/firestore-multimodal-genai/extension.yaml +++ b/firestore-multimodal-genai/extension.yaml @@ -268,6 +268,22 @@ params: required: false immutable: false + - param: RESPONSE_MIME_TYPE + label: Output response mimetype of the generated candidate text. + description: >- + Supported mimetype: + - text/plain: (default) Text output. + - application/json: JSON response in the candidates. + The model needs to be prompted to output the appropriate response type, otherwise the behavior is undefined. + type: select + options: + - label: JSON + value: application/json + - label: Text + value: text/plain + default: text/plain + required: false + - param: CANDIDATE_COUNT label: Candidate count description: >-