Skip to content

Commit

Permalink
feat(firestore-translate-text): optionally allow genkit for translati…
Browse files Browse the repository at this point in the history
…ons (#2228)

* feat(firestore-translate-text): optionally allow the use of Gemini 1.5 Pro for translations

* chore(firestore-translate-text): bump extension version

* chore(firestore-translate-text): add JSDoc comments to new code
  • Loading branch information
cabljac authored Dec 10, 2024
1 parent 45b9791 commit 7df7ee8
Show file tree
Hide file tree
Showing 9 changed files with 3,929 additions and 430 deletions.
4 changes: 4 additions & 0 deletions firestore-translate-text/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## Version 0.1.20

feat - add optional Gemini translations powered by Firebase Genkit

## Version 0.1.19

fixed - bump dependencies, fix vulnerabilities
Expand Down
18 changes: 18 additions & 0 deletions firestore-translate-text/PREINSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,24 @@ of languages, such as `en,fr,de`. See the [supported languages list](https://clo

Before installing this extension, make sure that you've [set up a Cloud Firestore database](https://firebase.google.com/docs/firestore/quickstart) in your Firebase project.

#### Optional Genkit Integration

This extension optionally supports Genkit as an alternative to the Google Cloud Translation API for performing translations. With Genkit, you can leverage large language models such as Google AI Gemini or Vertex AI Gemini to generate translations.

##### How it works:
Genkit Integration allows you to use the powerful Gemini 1.5 Pro model for translations. When enabled, the extension uses the specified Genkit provider to perform the translations instead of the default Cloud Translation API.

You can choose between:

- Google AI: Uses the googleai plugin with an API key.
- Vertex AI: Uses the vertexai plugin and connects to your Google Cloud Vertex AI endpoint.

In theory, a large language model like Gemini 1.5 Pro may have more contextual understanding. For example in the sentence `I left my keys in the bank` the model may understand whether `bank` refers to a financial institution or a riverbank, and may provide a more accurate translation.

##### Notes:
- Using Genkit may incur additional charges based on your model provider (Google AI or Vertex AI).
- If you do not wish to use Genkit, the extension defaults to the Cloud Translation API.

#### Billing
To install an extension, your project must be on the [Blaze (pay as you go) plan](https://firebase.google.com/pricing)

Expand Down
31 changes: 31 additions & 0 deletions firestore-translate-text/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,24 @@ of languages, such as `en,fr,de`. See the [supported languages list](https://clo

Before installing this extension, make sure that you've [set up a Cloud Firestore database](https://firebase.google.com/docs/firestore/quickstart) in your Firebase project.

#### Optional Genkit Integration

This extension optionally supports Genkit as an alternative to the Google Cloud Translation API for performing translations. With Genkit, you can leverage large language models such as Google AI Gemini or Vertex AI Gemini to generate translations.

##### How it works:
Genkit Integration allows you to use the powerful Gemini 1.5 Pro model for translations. When enabled, the extension uses the specified Genkit provider to perform the translations instead of the default Cloud Translation API.

You can choose between:

- Google AI: Uses the googleai plugin with an API key.
- Vertex AI: Uses the vertexai plugin and connects to your Google Cloud Vertex AI endpoint.

In theory, a large language model like Gemini 1.5 Pro may have more contextual understanding. For example in the sentence `I left my keys in the bank` the model may understand whether `bank` refers to a financial institution or a riverbank, and may provide a more accurate translation.

##### Notes:
- Using Genkit may incur additional charges based on your model provider (Google AI or Vertex AI).
- If you do not wish to use Genkit, the extension defaults to the Cloud Translation API.

#### Billing
To install an extension, your project must be on the [Blaze (pay as you go) plan](https://firebase.google.com/pricing)

Expand Down Expand Up @@ -70,6 +88,15 @@ To install an extension, your project must be on the [Blaze (pay as you go) plan
* Languages field name: What is the name of the field that contains the languages that you want to translate into? This field is optional. If you don't specify it, the extension will use the languages specified in the LANGUAGES parameter.


* Use Genkit for translations?: If you want to use Genkit to perform translations, select "Yes" and provide the necessary configuration parameters. If you select "No", the extension will use Google Cloud Translation API.


* Genkit Gemini provider: If you selected to use Genkit to perform translations, please provide the name of the Gemini API you want to use.


* Google AI API key: If you selected to use Genkit with Google AI to perform translations, please provide a Google AI API key




**Cloud Functions:**
Expand All @@ -84,6 +111,8 @@ To install an extension, your project must be on the [Blaze (pay as you go) plan

* translate.googleapis.com (Reason: To use Google Translate to translate strings into your specified target languages.)

* aiplatform.googleapis.com (Reason: This extension uses the Vertex AI multimodal model for embedding images, if configured to do so.)



**Access Required**:
Expand All @@ -93,3 +122,5 @@ To install an extension, your project must be on the [Blaze (pay as you go) plan
This extension will operate with the following project IAM roles:

* datastore.user (Reason: Allows the extension to write translated strings to Cloud Firestore.)

* aiplatform.user (Reason: This extension requires access to Vertex AI to create, update and query a Vertex Matching Engine index.)
46 changes: 45 additions & 1 deletion firestore-translate-text/extension.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.

name: firestore-translate-text
version: 0.1.19
version: 0.1.20
specVersion: v1beta

tags: [ai]
Expand Down Expand Up @@ -47,11 +47,20 @@ apis:
reason:
To use Google Translate to translate strings into your specified target
languages.
- apiName: aiplatform.googleapis.com
reason:
This extension uses the Vertex AI multimodal model for embedding images,
if configured to do so.

roles:
- role: datastore.user
reason: Allows the extension to write translated strings to Cloud Firestore.

- role: aiplatform.user
reason: >-
This extension requires access to Vertex AI to create, update and query a
Vertex Matching Engine index.
resources:
- name: fstranslate
type: firebaseextensions.v1beta.function
Expand Down Expand Up @@ -130,6 +139,41 @@ params:
default: languages
required: false

- param: USE_GENKIT
label: Use Genkit for translations?
description: >
If you want to use Genkit to perform translations, select "Yes" and
provide the necessary configuration parameters. If you select "No", the
extension will use Google Cloud Translation API.
type: select
required: true
options:
- label: Yes
value: true
- label: No
value: false

- param: GEMINI_PROVIDER
label: Genkit Gemini provider
description: >
If you selected to use Genkit to perform translations, please provide the
name of the Gemini API you want to use.
type: select
required: false
options:
- label: Google AI
value: googleai
- label: Vertex AI
value: vertexai

- param: GOOGLE_AI_API_KEY
label: Google AI API key
description: >
If you selected to use Genkit with Google AI to perform translations,
please provide a Google AI API key
type: secret
required: false

# - param: DO_BACKFILL
# label: Translate existing documents?
# description: >
Expand Down
Loading

0 comments on commit 7df7ee8

Please sign in to comment.