Skip to content

Commit 0a64f98

Browse files
cabljacGustolandia
andauthored
release: 10/12/2024 (#2230)
* Fix: Add support for handling multiple schemas from a comma-separated list in schema-loader-utils - Updated `readSchemas` in `schema-loader-utils.ts` to correctly parse and handle multiple schema files passed as a comma-separated list. - Added a test case to validate functionality for multiple schemas in `schema-loader-utils.test.ts`. Addresses issue #2087. [Bug] Fix issue #2087: Handle multiple schema files in gen-schema-views script * chore(fs-bq-schema-views): bump package version (#2225) * feat(firestore-translate-text): optionally allow genkit for translations (#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 --------- Co-authored-by: Gustolandia <Gustavo.ricou@gmail.com>
1 parent ce22524 commit 0a64f98

File tree

15 files changed

+4060
-510
lines changed

15 files changed

+4060
-510
lines changed

firestore-bigquery-export/firestore-bigquery-change-tracker/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

firestore-bigquery-export/scripts/gen-schema-view/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@firebaseextensions/fs-bq-schema-views",
3-
"version": "0.4.8",
3+
"version": "0.4.9",
44
"description": "Generate strongly-typed BigQuery Views based on raw JSON",
55
"main": "./lib/index.js",
66
"repository": {

firestore-bigquery-export/scripts/gen-schema-view/src/__tests__/schema-loader-utils/schema-loader-utils.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,19 @@ describe("filesystem schema loading", () => {
7676
const schemas = schema_loader_utils.readSchemas([globPattern]);
7777
expect(Object.keys(schemas)).to.have.members(results);
7878
});
79+
it("should load schemas from a comma-separated list of file paths", () => {
80+
const schemaFiles = `${schemaDir}/full-directory/schema-1.json,${schemaDir}/full-directory/schema-2.json`;
81+
const schemas = Object.keys(schema_loader_utils.readSchemas([schemaFiles]));
82+
expect(schemas.length).to.equal(2);
83+
expect(schemas).to.include(
84+
schema_loader_utils.filePathToSchemaName(
85+
`${schemaDir}/full-directory/schema-1.json`
86+
)
87+
);
88+
expect(schemas).to.include(
89+
schema_loader_utils.filePathToSchemaName(
90+
`${schemaDir}/full-directory/schema-2.json`
91+
)
92+
);
93+
});
7994
});

firestore-bigquery-export/scripts/gen-schema-view/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ async function parseConfig(): Promise<CliConfig> {
174174
program.outputHelp();
175175
process.exit(1);
176176
}
177+
177178
return {
178179
projectId: program.project,
179180
bigQueryProjectId: program.bigQueryProject,

firestore-bigquery-export/scripts/gen-schema-view/src/schema-loader-utils.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,10 @@ function resolveFilePath(filePath: string): string {
6363

6464
function expandGlobs(globs: string[]): string[] {
6565
let results = [];
66-
for (var i = 0; i < globs.length; i++) {
67-
const globResults = glob.sync(globs[i]);
66+
// Split any comma-separated globs into individual paths
67+
const expandedGlobs = globs.flatMap((g) => g.split(",").map((s) => s.trim()));
68+
for (const globPath of expandedGlobs) {
69+
const globResults = glob.sync(globPath);
6870
results = results.concat(globResults);
6971
}
7072
return results;

firestore-translate-text/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## Version 0.1.20
2+
3+
feat - add optional Gemini translations powered by Firebase Genkit
4+
15
## Version 0.1.19
26

37
fixed - bump dependencies, fix vulnerabilities

firestore-translate-text/PREINSTALL.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,24 @@ of languages, such as `en,fr,de`. See the [supported languages list](https://clo
3333

3434
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.
3535

36+
#### Optional Genkit Integration
37+
38+
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.
39+
40+
##### How it works:
41+
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.
42+
43+
You can choose between:
44+
45+
- Google AI: Uses the googleai plugin with an API key.
46+
- Vertex AI: Uses the vertexai plugin and connects to your Google Cloud Vertex AI endpoint.
47+
48+
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.
49+
50+
##### Notes:
51+
- Using Genkit may incur additional charges based on your model provider (Google AI or Vertex AI).
52+
- If you do not wish to use Genkit, the extension defaults to the Cloud Translation API.
53+
3654
#### Billing
3755
To install an extension, your project must be on the [Blaze (pay as you go) plan](https://firebase.google.com/pricing)
3856

firestore-translate-text/README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,24 @@ of languages, such as `en,fr,de`. See the [supported languages list](https://clo
4141

4242
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.
4343

44+
#### Optional Genkit Integration
45+
46+
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.
47+
48+
##### How it works:
49+
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.
50+
51+
You can choose between:
52+
53+
- Google AI: Uses the googleai plugin with an API key.
54+
- Vertex AI: Uses the vertexai plugin and connects to your Google Cloud Vertex AI endpoint.
55+
56+
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.
57+
58+
##### Notes:
59+
- Using Genkit may incur additional charges based on your model provider (Google AI or Vertex AI).
60+
- If you do not wish to use Genkit, the extension defaults to the Cloud Translation API.
61+
4462
#### Billing
4563
To install an extension, your project must be on the [Blaze (pay as you go) plan](https://firebase.google.com/pricing)
4664

@@ -70,6 +88,15 @@ To install an extension, your project must be on the [Blaze (pay as you go) plan
7088
* 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.
7189

7290

91+
* 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.
92+
93+
94+
* Genkit Gemini provider: If you selected to use Genkit to perform translations, please provide the name of the Gemini API you want to use.
95+
96+
97+
* Google AI API key: If you selected to use Genkit with Google AI to perform translations, please provide a Google AI API key
98+
99+
73100

74101

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

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

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

88117

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

95124
* datastore.user (Reason: Allows the extension to write translated strings to Cloud Firestore.)
125+
126+
* aiplatform.user (Reason: This extension requires access to Vertex AI to create, update and query a Vertex Matching Engine index.)

firestore-translate-text/extension.yaml

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# limitations under the License.
1414

1515
name: firestore-translate-text
16-
version: 0.1.19
16+
version: 0.1.20
1717
specVersion: v1beta
1818

1919
tags: [ai]
@@ -47,11 +47,20 @@ apis:
4747
reason:
4848
To use Google Translate to translate strings into your specified target
4949
languages.
50+
- apiName: aiplatform.googleapis.com
51+
reason:
52+
This extension uses the Vertex AI multimodal model for embedding images,
53+
if configured to do so.
5054

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

59+
- role: aiplatform.user
60+
reason: >-
61+
This extension requires access to Vertex AI to create, update and query a
62+
Vertex Matching Engine index.
63+
5564
resources:
5665
- name: fstranslate
5766
type: firebaseextensions.v1beta.function
@@ -130,6 +139,41 @@ params:
130139
default: languages
131140
required: false
132141

142+
- param: USE_GENKIT
143+
label: Use Genkit for translations?
144+
description: >
145+
If you want to use Genkit to perform translations, select "Yes" and
146+
provide the necessary configuration parameters. If you select "No", the
147+
extension will use Google Cloud Translation API.
148+
type: select
149+
required: true
150+
options:
151+
- label: Yes
152+
value: true
153+
- label: No
154+
value: false
155+
156+
- param: GEMINI_PROVIDER
157+
label: Genkit Gemini provider
158+
description: >
159+
If you selected to use Genkit to perform translations, please provide the
160+
name of the Gemini API you want to use.
161+
type: select
162+
required: false
163+
options:
164+
- label: Google AI
165+
value: googleai
166+
- label: Vertex AI
167+
value: vertexai
168+
169+
- param: GOOGLE_AI_API_KEY
170+
label: Google AI API key
171+
description: >
172+
If you selected to use Genkit with Google AI to perform translations,
173+
please provide a Google AI API key
174+
type: secret
175+
required: false
176+
133177
# - param: DO_BACKFILL
134178
# label: Translate existing documents?
135179
# description: >

0 commit comments

Comments
 (0)