Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(firestore-genai-chatbot) added support for response_mime_type #514

Open
wants to merge 3 commits into
base: next
Choose a base branch
from
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
16 changes: 16 additions & 0 deletions firestore-genai-chatbot/extension.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: >-
Expand Down
2 changes: 1 addition & 1 deletion firestore-genai-chatbot/functions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.1.1",
"@google/generative-ai": "^0.11.4",
"@types/jest": "^29.5.12",
"firebase-admin": "^12.1.0",
"firebase-functions": "^4.9.0",
Expand Down
2 changes: 2 additions & 0 deletions firestore-genai-chatbot/functions/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export interface Config {
safetySettings?: GoogleAISafetySetting[] | VertexSafetySetting[];
provider: GenerativeAIProvider;
maxOutputTokens?: number;
responseMimeType?: string;
}

function getSafetySettings(): GoogleAISafetySetting[] | VertexSafetySetting[] {
Expand Down Expand Up @@ -116,6 +117,7 @@ const config: Config = {
maxOutputTokens: process.env.MAX_OUTPUT_TOKENS
? parseInt(process.env.MAX_OUTPUT_TOKENS)
: undefined,
responseMimeType: process.env.RESPONSE_MIME_TYPE || 'text/plain',
};

export default config;
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {DiscussionClient, Message} from './base_class';
import {GoogleGenerativeAI, InputContent} from '@google/generative-ai';
import {GoogleGenerativeAI, Content} from '@google/generative-ai';
import {logger} from 'firebase-functions/v1';
import {SafetySetting} from '@google/generative-ai';

Expand All @@ -15,6 +15,7 @@ interface GeminiChatOptions {
location: string;
context?: string;
safetySettings: SafetySetting[];
responseMimeType?: string;
}

type ApiMessage = {
Expand Down Expand Up @@ -80,6 +81,7 @@ export class GeminiDiscussionClient extends DiscussionClient<
temperature: options.temperature,
maxOutputTokens: options.maxOutputTokens,
candidateCount: options.candidateCount,
responseMimeType: options.responseMimeType,
},
safetySettings: options.safetySettings,
});
Expand Down Expand Up @@ -112,7 +114,7 @@ export class GeminiDiscussionClient extends DiscussionClient<
}

private messagesToApi(messages: Message[]) {
const out: InputContent[] = [];
const out: Content[] = [];
for (const message of messages) {
if (!message.prompt || !message.response) {
// logs.warnMissingPromptOrResponse(message.path!);
Expand Down
Loading