Skip to content
Closed
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
4 changes: 4 additions & 0 deletions firestore-genai-chatbot/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## Version 0.0.10

- Add docs on regional support for Gemini APIs

## Version 0.0.9

- fix typo in documentation
Expand Down
6 changes: 5 additions & 1 deletion firestore-genai-chatbot/PREINSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ Use this extension to easily deploy a chatbot using Gemini models, stored and ma

On install you will be asked to provide:

- **Gemini API Provider** This extension makes use of the Gemini family of models. Currently the extension supports the Google AI Gemini API and the Vertex AI Gemini API. Learn more about the differences between the Google AI and Vertex AI Gemini APIs here.
- **Gemini API Provider** This extension makes use of the Gemini family of models. Currently the extension supports the Google AI Gemini API and the Vertex AI Gemini API. Learn more about the differences between the Google AI and Vertex AI Gemini APIs [here](https://cloud.google.com/vertex-ai/docs/generative-ai/migrate/migrate-google-ai).

Note that Generative AI on Vertex AI is only available in the regions listed [here](https://cloud.google.com/vertex-ai/docs/generative-ai/learn/locations-genai).

A list of languages and regions supported by the Gemini API on Google AI is [here](https://ai.google.dev/available_regions).

- **Gemini Model**: Input the name of the Gemini model you would like to use. To view available models for each provider, see:
- [Vertex AI Gemini models](https://cloud.google.com/vertex-ai/docs/generative-ai/learn/models)
Expand Down
8 changes: 6 additions & 2 deletions firestore-genai-chatbot/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@

On install you will be asked to provide:

- **Gemini API Provider** This extension makes use of the Gemini family of models. Currently the extension supports the Google AI Gemini API and the Vertex AI Gemini API. Learn more about the differences between the Google AI and Vertex AI Gemini APIs here.
- **Gemini API Provider** This extension makes use of the Gemini family of models. Currently the extension supports the Google AI Gemini API and the Vertex AI Gemini API. Learn more about the differences between the Google AI and Vertex AI Gemini APIs [here](https://cloud.google.com/vertex-ai/docs/generative-ai/migrate/migrate-google-ai).

Note that Generative AI on Vertex AI is only available in the regions listed [here](https://cloud.google.com/vertex-ai/docs/generative-ai/learn/locations-genai).

A list of languages and regions supported by the Gemini API on Google AI is [here](https://ai.google.dev/available_regions).

- **Gemini Model**: Input the name of the Gemini model you would like to use. To view available models for each provider, see:
- [Vertex AI Gemini models](https://cloud.google.com/vertex-ai/docs/generative-ai/learn/models)
Expand Down Expand Up @@ -83,7 +87,7 @@ This extension uses other Firebase and Google Cloud Platform services, which hav

* Order Field: The field by which to order when fetching conversation history. If absent when processing begins, the current timestamp will be written to this field. Sorting will be in descending order.

* Cloud Functions location: Where do you want to deploy the functions created for this extension? For help selecting a location, refer to the [location selection guide](https://firebase.google.com/docs/functions/locations).
* Cloud Functions location: Where do you want to deploy the functions created for this extension? For help selecting a location, refer to the [location selection guide](https://firebase.google.com/docs/functions/locations). Note that Generative AI on Vertex AI is only available in the regions listed [here](https://cloud.google.com/vertex-ai/docs/generative-ai/learn/locations-genai). A list of languages and regions supported by the Gemini API on Google AI is [here](https://ai.google.dev/available_regions).

* Context: Contextual preamble for the generative AI model. A string giving context for the discussion.

Expand Down
8 changes: 6 additions & 2 deletions firestore-genai-chatbot/extension.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: firestore-genai-chatbot
version: 0.0.9
version: 0.0.10
specVersion: v1beta

icon: icon.png
Expand Down Expand Up @@ -161,7 +161,11 @@ params:
description: >-
Where do you want to deploy the functions created for this extension? For
help selecting a location, refer to the [location selection
guide](https://firebase.google.com/docs/functions/locations).
guide](https://firebase.google.com/docs/functions/locations). Note that
Generative AI on Vertex AI is only available in the regions listed
[here](https://cloud.google.com/vertex-ai/docs/generative-ai/learn/locations-genai).
A list of languages and regions supported by the Gemini API on Google AI
is [here](https://ai.google.dev/available_regions).
type: select
options:
- label: Iowa (us-central1)
Expand Down
4 changes: 4 additions & 0 deletions firestore-multimodal-genai/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## Version 0.0.9

- Add docs on regional support for Gemini APIs

## Version 0.0.8

- fix typo in documentation
Expand Down
2 changes: 1 addition & 1 deletion firestore-multimodal-genai/POSTINSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Note: You can also use the Firebase Admin SDK to add a document:
const ref = await admin
.firestore()
.collection("${param:COLLECTION_NAME}")
.add({ ... }) // Include values for ${param:VARIABLE_FIELDS} fields
.add({ ... })

ref.onSnapshot(snap => {
if (snap.get('${param:RESPONSE_FIELD}')) console.log(
Expand Down
9 changes: 8 additions & 1 deletion firestore-multimodal-genai/PREINSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ This extension allows you to perform generative tasks using the Gemini API, a cu

On installation, you will be asked to provide the following information:

**Gemini API Provider**: This extension makes use of the Gemini family of large language models. Currently the extension supports the Google AI Gemini API (for developers) and the Vertex AI Gemini API. Learn more about the differences between the Google AI and Vertex AI Gemini APIs here.
- **Gemini API Provider** This extension makes use of the Gemini family of models. Currently the extension supports the Google AI Gemini API and the Vertex AI Gemini API. Learn more about the differences between the Google AI and Vertex AI Gemini APIs [here](https://cloud.google.com/vertex-ai/docs/generative-ai/migrate/migrate-google-ai).

Note that Generative AI on Vertex AI is only available in the regions listed [here](https://cloud.google.com/vertex-ai/docs/generative-ai/learn/locations-genai).

A list of languages and regions supported by the Gemini API on Google AI is [here](https://ai.google.dev/available_regions).

**Gemini Model**: Input the name of which Gemini model you would like to use. To view available models for each provider, see:

- [Vertex AI Gemini models](https://cloud.google.com/vertex-ai/docs/generative-ai/learn/models)
Expand All @@ -16,6 +21,8 @@ This extension will listen to the specified collection for new documents. When s
2. Query the Gemini API to generate a response based on the prompt.
3. Write the response from the Model API back to the triggering document in the response field.

Additionally the extension deploys a callable function, which may be called with data containing the values for handlebar substitution.

Note that the extension only supports top-level handlebars variables, substitution into nested handlebar templates is not supported.

Each instance of the extension should be configured to perform one particular task. If you have multiple tasks, you can install multiple instances.
Expand Down
15 changes: 12 additions & 3 deletions firestore-multimodal-genai/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@

On installation, you will be asked to provide the following information:

**Gemini API Provider**: This extension makes use of the Gemini family of large language models. Currently the extension supports the Google AI Gemini API (for developers) and the Vertex AI Gemini API. Learn more about the differences between the Google AI and Vertex AI Gemini APIs here.
- **Gemini API Provider** This extension makes use of the Gemini family of models. Currently the extension supports the Google AI Gemini API and the Vertex AI Gemini API. Learn more about the differences between the Google AI and Vertex AI Gemini APIs [here](https://cloud.google.com/vertex-ai/docs/generative-ai/migrate/migrate-google-ai).

Note that Generative AI on Vertex AI is only available in the regions listed [here](https://cloud.google.com/vertex-ai/docs/generative-ai/learn/locations-genai).

A list of languages and regions supported by the Gemini API on Google AI is [here](https://ai.google.dev/available_regions).

**Gemini Model**: Input the name of which Gemini model you would like to use. To view available models for each provider, see:

- [Vertex AI Gemini models](https://cloud.google.com/vertex-ai/docs/generative-ai/learn/models)
Expand All @@ -24,6 +29,8 @@ This extension will listen to the specified collection for new documents. When s
2. Query the Gemini API to generate a response based on the prompt.
3. Write the response from the Model API back to the triggering document in the response field.

Additionally the extension deploys a callable function, which may be called with data containing the values for handlebar substitution.

Note that the extension only supports top-level handlebars variables, substitution into nested handlebar templates is not supported.

Each instance of the extension should be configured to perform one particular task. If you have multiple tasks, you can install multiple instances.
Expand Down Expand Up @@ -112,7 +119,7 @@ This extension uses other Firebase and Google Cloud Platform services, which hav

* Response Field: The field in the message document into which to put the response.

* Cloud Functions location: Where do you want to deploy the functions created for this extension? For help selecting a location, refer to the [location selection guide](https://firebase.google.com/docs/functions/locations).
* Cloud Functions location: Where do you want to deploy the functions created for this extension? For help selecting a location, refer to the [location selection guide](https://firebase.google.com/docs/functions/locations). Note that Generative AI on Vertex AI is only available in the regions listed [here](https://cloud.google.com/vertex-ai/docs/generative-ai/learn/locations-genai). A list of languages and regions supported by the Gemini API on Google AI is [here](https://ai.google.dev/available_regions).

* Temperature: Controls the randomness of the output. Values can range over [0,1], inclusive. A value closer to 1 will produce responses that are more varied, while a value closer to 0 will typically result in less surprising responses from the model.

Expand All @@ -136,7 +143,9 @@ This extension uses other Firebase and Google Cloud Platform services, which hav

**Cloud Functions:**

* **generateText:** Listens to Firestore data writes to generate conversations.
* **generateOnCall:** A callable function to perform generative AI tasks.

* **generateText:** Listens to Firestore data writes to perform generative AI tasks.



Expand Down
19 changes: 16 additions & 3 deletions firestore-multimodal-genai/extension.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: firestore-multimodal-genai
version: 0.0.8
version: 0.0.9
specVersion: v1beta

icon: icon.png
Expand Down Expand Up @@ -64,10 +64,19 @@ roles:
Vertex AI if this provider is chosen.

resources:
- name: generateOnCall
type: firebaseextensions.v1beta.function
description: >-
A callable function to perform generative AI tasks.
properties:
location: ${LOCATION}
httpsTrigger: {}
runtime: nodejs18

- name: generateText
type: firebaseextensions.v1beta.function
description: >-
Listens to Firestore data writes to generate conversations.
Listens to Firestore data writes to perform generative AI tasks.
properties:
availableMemoryMb: 2048
timeout: 540s
Expand Down Expand Up @@ -170,7 +179,11 @@ params:
description: >-
Where do you want to deploy the functions created for this extension? For
help selecting a location, refer to the [location selection
guide](https://firebase.google.com/docs/functions/locations).
guide](https://firebase.google.com/docs/functions/locations). Note that
Generative AI on Vertex AI is only available in the regions listed
[here](https://cloud.google.com/vertex-ai/docs/generative-ai/learn/locations-genai).
A list of languages and regions supported by the Gemini API on Google AI
is [here](https://ai.google.dev/available_regions).
type: select
options:
- label: Iowa (us-central1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ jest.mock('../../src/config', () => ({
projectId: 'demo-test',
instanceId: 'demo-test',
provider: 'google-ai',
candidates: {
field: 'candidates',
count: 1,
shouldIncludeCandidatesField: false,
},
},
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ jest.mock('../../src/config', () => ({
projectId: 'demo-test',
instanceId: 'demo-test',
provider: 'vertex-ai',
candidates: {
field: 'candidates',
count: 1,
shouldIncludeCandidatesField: false,
},
},
}));

Expand Down
38 changes: 19 additions & 19 deletions firestore-multimodal-genai/functions/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions firestore-multimodal-genai/functions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
},
"main": "lib/index.js",
"dependencies": {
"@google-ai/generativelanguage": "^2.0.0",
"@google-cloud/aiplatform": "^3.0.0",
"@google-cloud/vertexai": "^0.2.1",
"@google/generative-ai": "^0.1.3",
"@google-ai/generativelanguage": "^2.1.0",
"@google-cloud/aiplatform": "^3.15.0",
"@google-cloud/vertexai": "^0.5.0",
"@google/generative-ai": "^0.3.1",
"@types/jest": "^29.5.12",
"@types/mustache": "^4.2.2",
"firebase-admin": "^11.5.0",
Expand Down
9 changes: 5 additions & 4 deletions firestore-multimodal-genai/functions/src/__mocks__/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ export default {
collectionName: 'discussions',
prompt: 'test prompt',
responseField: 'output',
candidateCount: 1,
provider: 'vertex-ai',
apiKey: process.env.API_KEY,
bucketName: 'demo-gcp.appspot.com',
imageField: 'image',
customRagHookUrl: 'https://www.test.com',
ragHookInputFields: ['test'],
ragHookOutputFields: ['foo'],
candidates: {
field: 'candidates',
count: 1,
shouldIncludeCandidatesField: false,
},
};
40 changes: 18 additions & 22 deletions firestore-multimodal-genai/functions/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,18 @@ export interface Config {
temperature?: number;
topP?: number;
topK?: number;
candidateCount?: number;
candidatesField?: string;
candidates: {
field: string;
count: number;
shouldIncludeCandidatesField: boolean;
};
maxOutputTokens?: number;
maxOutputTokensVertex?: number;
provider?: string;
apiKey?: string;
safetySettings?: GoogleAISafetySetting[] | VertexSafetySetting[];
bucketName?: string;
imageField: string;
// ragConfig: {
// customRagHookUrl?: string;
// customRagHookApiKey?: string;
// ragHookInputFields?: string[];
// ragHookOutputFields?: string[];
// };
}

function getSafetySettings(): GoogleAISafetySetting[] | VertexSafetySetting[] {
Expand Down Expand Up @@ -87,6 +84,18 @@ function getSafetySettings(): GoogleAISafetySetting[] | VertexSafetySetting[] {

const defaultBucketName = `${process.env.PROJECT_ID}.appspot.com`;

const candidates = {
field: process.env.CANDIDATES_FIELD || 'candidates',
count: process.env.CANDIDATE_COUNT
? parseInt(process.env.CANDIDATE_COUNT)
: 1,
shouldIncludeCandidatesField:
process.env.GENERATIVE_AI_PROVIDER === 'generative' &&
process.env.CANDIDATES_FIELD &&
process.env.CANDIDATE_COUNT &&
parseInt(process.env.CANDIDATE_COUNT) > 1,
};

export default {
vertex: {
model: process.env.MODEL!,
Expand All @@ -108,10 +117,7 @@ export default {
: undefined,
topP: process.env.TOP_P ? parseFloat(process.env.TOP_P) : undefined,
topK: process.env.TOP_K ? parseInt(process.env.TOP_K) : undefined,
candidateCount: process.env.CANDIDATE_COUNT
? parseInt(process.env.CANDIDATE_COUNT)
: 1,
candidatesField: process.env.CANDIDATES_FIELD || 'candidates',
candidates,
provider: process.env.GENERATIVE_AI_PROVIDER,
maxOutputTokensVertex: process.env.MAX_OUTPUT_TOKENS
? parseInt(process.env.MAX_OUTPUT_TOKENS)
Expand All @@ -120,14 +126,4 @@ export default {
safetySettings: getSafetySettings(),
bucketName: process.env.BUCKET_NAME || defaultBucketName,
imageField: process.env.IMAGE_FIELD || 'image',
// ragConfig: {
// customRagHookUrl: process.env.CUSTOM_RAG_HOOK_URL,
// ragHookInputFields: process.env.RAG_HOOK_INPUT_FIELDS
// ? process.env.RAG_HOOK_INPUT_FIELDS.split(',')
// : undefined,
// ragHookOutputFields: process.env.RAG_HOOK_OUTPUT_FIELDS
// ? process.env.RAG_HOOK_OUTPUT_FIELDS.split(',')
// : undefined,
// // customRagHookApiKey: process.env.RAG_HOOK_API_KEY,
// },
};
Loading