Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
85 commits
Select commit Hold shift + click to select a range
28ecb65
Updates example code for Next.js in docs (#857)
philnash Sep 17, 2024
8865e7d
fix(js): disabled explicit json mode when using tools (#888)
cabljac Sep 17, 2024
8611c7e
Add usage and safety score logs for output candidates (#919)
schnecle Sep 17, 2024
0e8d9b8
fix: correctly pass local auth context when doing runFlow (#920)
pavelgj Sep 17, 2024
2940fd5
Update the flow name extraction regex to support the scenario where t…
bryanatkinson Sep 18, 2024
09014eb
Truncate logs based on utf bytes instead of characters. There's no gu…
bryanatkinson Sep 19, 2024
75a16af
feat(js/plugins/vertexai): strict json mode (#890)
cabljac Sep 23, 2024
50cfbe8
fix(docs): replace obsolete package name (#943)
DenisVCode Sep 23, 2024
486dc9d
fix model name lookup in dotprompt plugin and add a test (#933)
dhiaayachi Sep 24, 2024
1f3ca67
chore: update express to 4.21.0 (#956)
tonybaroneee Sep 25, 2024
49c0352
docs(js): update token fetching in ollama docs (#918)
cabljac Sep 26, 2024
4510fff
feat(js): add llama-3.2 support to model garden plugin (#969)
huangjeff5 Sep 26, 2024
03943bc
chore: bump @genkit-ai/tools-common version to @genkit-ai/tools-commo…
gh-action-bump-version Sep 27, 2024
ef93f3f
chore: bump CLI version to genkit@0.5.14
gh-action-bump-version Sep 27, 2024
a15c96b
chore: bump @genkit-ai/core version to @genkit-ai/core@0.5.14
gh-action-bump-version Sep 27, 2024
8ac0750
chore: bump @genkit-ai/ai version to @genkit-ai/ai@0.5.14
gh-action-bump-version Sep 27, 2024
650f3ca
chore: bump @genkit-ai/flow version to @genkit-ai/flow@0.5.14
gh-action-bump-version Sep 27, 2024
696266d
chore: bump genkitx-chromadb version to genkitx-chromadb0.5.14
gh-action-bump-version Sep 27, 2024
69454e2
chore: bump @genkit-ai/dev-local-vectorstore version to @genkit-ai/de…
gh-action-bump-version Sep 27, 2024
e3276c4
chore: bump @genkit-ai/dotprompt version to @genkit-ai/dotprompt@0.5.14
gh-action-bump-version Sep 27, 2024
d60c0ee
chore: bump @genkit-ai/evaluator version to @genkit-ai/evaluator@0.5.14
gh-action-bump-version Sep 27, 2024
87153d8
chore: bump @genkit-ai/firebase version to @genkit-ai/firebase@0.5.14
gh-action-bump-version Sep 27, 2024
56ea3d4
chore: bump @genkit-ai/google-cloud version to @genkit-ai/google-clou…
gh-action-bump-version Sep 27, 2024
5578c15
chore: bump @genkit-ai/googleai version to @genkit-ai/googleai@0.5.14
gh-action-bump-version Sep 27, 2024
8bb2556
chore: bump genkitx-langchain version to genkitx-langchain@0.5.14
gh-action-bump-version Sep 27, 2024
eea8945
chore: bump genkitx-ollama version to genkitx-ollama@0.5.14
gh-action-bump-version Sep 27, 2024
e78ee12
chore: bump genkitx-pinecone version to genkitx-pinecone@0.5.14
gh-action-bump-version Sep 27, 2024
81e4b13
chore: bump @genkit-ai/vertexai version to @genkit-ai/vertexai@0.5.14
gh-action-bump-version Sep 27, 2024
9513f6d
chore: s/GenKit/Genkit/ 🤦
pavelgj Sep 28, 2024
42da470
Set min version for cloud-trace-exporter to 2.4.1 (#984)
MichaelDoyle Oct 1, 2024
1ce4f38
chore: update to pnpm v9.11 (#940) (#941)
tonybaroneee Oct 1, 2024
f90974c
chore: update to pnpm v9.12 (#1000)
tonybaroneee Oct 3, 2024
895249a
Update pull_request_template.md
pavelgj Oct 3, 2024
231591b
feat: added support for image editing and upscaling for imagen3 (#989)
pavelgj Oct 3, 2024
aeb91b0
fix(js): fix streaming json mode in gemini plugins (#1003)
cabljac Oct 3, 2024
efadaa7
chore: bump @genkit-ai/tools-common version to @genkit-ai/tools-commo…
gh-action-bump-version Oct 4, 2024
1cc153f
chore: bump CLI version to genkit@0.5.15
gh-action-bump-version Oct 4, 2024
1485430
chore: bump @genkit-ai/core version to @genkit-ai/core@0.5.15
gh-action-bump-version Oct 4, 2024
b1174f8
chore: bump @genkit-ai/ai version to @genkit-ai/ai@0.5.15
gh-action-bump-version Oct 4, 2024
aaa0749
chore: bump @genkit-ai/flow version to @genkit-ai/flow@0.5.15
gh-action-bump-version Oct 4, 2024
c9de812
chore: bump genkitx-chromadb version to genkitx-chromadb0.5.15
gh-action-bump-version Oct 4, 2024
84062e0
chore: bump @genkit-ai/dev-local-vectorstore version to @genkit-ai/de…
gh-action-bump-version Oct 4, 2024
37e62d7
chore: bump @genkit-ai/dotprompt version to @genkit-ai/dotprompt@0.5.15
gh-action-bump-version Oct 4, 2024
bd532dd
chore: bump @genkit-ai/evaluator version to @genkit-ai/evaluator@0.5.15
gh-action-bump-version Oct 4, 2024
fa4ff92
chore: bump @genkit-ai/firebase version to @genkit-ai/firebase@0.5.15
gh-action-bump-version Oct 4, 2024
746e11b
chore: bump @genkit-ai/google-cloud version to @genkit-ai/google-clou…
gh-action-bump-version Oct 4, 2024
75ba059
chore: bump @genkit-ai/googleai version to @genkit-ai/googleai@0.5.15
gh-action-bump-version Oct 4, 2024
ad306c4
chore: bump genkitx-langchain version to genkitx-langchain@0.5.15
gh-action-bump-version Oct 4, 2024
56a1fc3
chore: bump genkitx-ollama version to genkitx-ollama@0.5.15
gh-action-bump-version Oct 4, 2024
ec8b2da
chore: bump genkitx-pinecone version to genkitx-pinecone@0.5.15
gh-action-bump-version Oct 4, 2024
6d1b9cf
chore: bump @genkit-ai/vertexai version to @genkit-ai/vertexai@0.5.15
gh-action-bump-version Oct 4, 2024
b5ddaea
docs: update vertex-ai.md
pavelgj Oct 4, 2024
8f28a89
chore: update vertex-ai.md
pavelgj Oct 4, 2024
96ea3e8
Added support for Gemini 1.5 Flash 8B and updated available versions …
chrisraygill Oct 4, 2024
e43c1d2
chore: bump @genkit-ai/tools-common version to @genkit-ai/tools-commo…
gh-action-bump-version Oct 4, 2024
0a13ba4
chore: bump CLI version to genkit@0.5.16
gh-action-bump-version Oct 4, 2024
becaf0f
chore: bump @genkit-ai/core version to @genkit-ai/core@0.5.16
gh-action-bump-version Oct 4, 2024
0891884
chore: bump @genkit-ai/ai version to @genkit-ai/ai@0.5.16
gh-action-bump-version Oct 4, 2024
1275b39
chore: bump @genkit-ai/flow version to @genkit-ai/flow@0.5.16
gh-action-bump-version Oct 4, 2024
9163cd0
chore: bump genkitx-chromadb version to genkitx-chromadb0.5.16
gh-action-bump-version Oct 4, 2024
9a19ab9
chore: bump @genkit-ai/dev-local-vectorstore version to @genkit-ai/de…
gh-action-bump-version Oct 4, 2024
e355d13
chore: bump @genkit-ai/dotprompt version to @genkit-ai/dotprompt@0.5.16
gh-action-bump-version Oct 4, 2024
d1d549f
chore: bump @genkit-ai/evaluator version to @genkit-ai/evaluator@0.5.16
gh-action-bump-version Oct 4, 2024
eb23395
chore: bump @genkit-ai/firebase version to @genkit-ai/firebase@0.5.16
gh-action-bump-version Oct 4, 2024
68c5b93
chore: bump @genkit-ai/google-cloud version to @genkit-ai/google-clou…
gh-action-bump-version Oct 4, 2024
ac4019e
chore: bump @genkit-ai/googleai version to @genkit-ai/googleai@0.5.16
gh-action-bump-version Oct 4, 2024
9fbac04
chore: bump genkitx-langchain version to genkitx-langchain@0.5.16
gh-action-bump-version Oct 4, 2024
1830e2d
chore: bump genkitx-ollama version to genkitx-ollama@0.5.16
gh-action-bump-version Oct 4, 2024
99ea10a
chore: bump genkitx-pinecone version to genkitx-pinecone@0.5.16
gh-action-bump-version Oct 4, 2024
7176f8f
chore: bump @genkit-ai/vertexai version to @genkit-ai/vertexai@0.5.16
gh-action-bump-version Oct 4, 2024
080108b
Revamp get started docs (#1016)
chrisraygill Oct 7, 2024
0098ff7
Update imports in index.md (#1018)
kevinthecheung Oct 7, 2024
b582bdc
chore(deps): bump express from 4.19.2 to 4.20.0 in /js (#1007)
dependabot[bot] Oct 9, 2024
53b8b97
chore(deps): bump body-parser from 1.20.2 to 1.20.3 in /js (#1006)
dependabot[bot] Oct 9, 2024
061ab92
fix: added rimraf for building on Windows (#1036)
CorieW Oct 10, 2024
2d38003
feat(js/plugins/ollama): add ollama embeddings back in (after rollbac…
cabljac Oct 21, 2024
ccaaa85
feat: add firestore retriever
cabljac Aug 16, 2024
e91fa9b
fix(go/plugins/firebase): address some review comments
cabljac Sep 16, 2024
9ceab80
chore(go): replace logs
cabljac Sep 23, 2024
7ee1b29
test: add emulator
cabljac Sep 23, 2024
fc4e6ec
feat: add emulator project
cabljac Sep 26, 2024
bf799ac
fix(go): fix retriever and test
cabljac Sep 26, 2024
085e217
docs(go/plugins/firebase): add docs
cabljac Oct 21, 2024
b136f3a
docs(go/plugins/firebase): fix sample app
cabljac Oct 21, 2024
3faff54
refactor(go/plugins/firebase): pass app to plugin instead of config p…
cabljac Oct 21, 2024
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
1 change: 0 additions & 1 deletion .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ Description here...

Checklist (if applicable):
- [ ] Tested (manually, unit tested, etc.)
- [ ] Changelog updated
- [ ] Docs updated
188 changes: 188 additions & 0 deletions docs-go/plugins/firebase.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@

# Firebase Genkit Plugin

The Firebase plugin for Genkit allows flows to integrate seamlessly with Firebase services, such as Firestore and Firebase Authentication.

This plugin includes initialization for Firebase, a retriever for Firestore, and Firebase Authentication integration for enhanced flow security.

## Prerequisites

Before using this plugin, ensure you have the following prerequisites:

1. **Google Cloud Account**: Sign up for a Google Cloud account if you don’t already have one [here](https://cloud.google.com/gcp).

2. **Google Cloud SDK**: Ensure that you have the [Google Cloud SDK (gcloud)](https://cloud.google.com/sdk/docs/install) installed on your local machine.

3. **Firebase Project**: Create a Firebase project or use an existing one. This project should have Firestore and Firebase Authentication enabled.

4. **APIs to Enable**:
- [Firestore API](https://console.cloud.google.com/apis/library/firestore.googleapis.com)
- [Firebase Authentication API](https://console.cloud.google.com/apis/library/identitytoolkit.googleapis.com)

You can enable these APIs from the [API Dashboard](https://console.cloud.google.com/apis/dashboard) of your Google Cloud project.

5. **Firebase CLI**: To locally run or interact with Firebase, ensure you have the Firebase CLI installed.

## Setup Instructions

### Firebase Initialization

To initialize Firebase in your Genkit project, first, import the `firebase` package:

```go
import "github.com/firebase/genkit/go/plugins/firebase"
```

### Configuration

You need to provide the Firebase configuration in the form of a `FirebasePluginConfig` struct. This example assumes that you are loading the project ID and Firestore collection from environment variables:

```go
// Load project ID and Firestore collection from environment variables
projectID := os.Getenv("FIREBASE_PROJECT_ID")
collectionName := os.Getenv("FIRESTORE_COLLECTION")

firebaseConfig := &firebase.FirebasePluginConfig{
App: firebaseApp, // Pass the pre-initialized Firebase app
Retrievers: []firebase.RetrieverOptions{
{
Name: "example-retriever",
Client: firestoreClient,
Collection: collectionName,
Embedder: embedder,
VectorField: "embedding",
ContentField: "text",
MetadataFields: []string{"metadata"},
Limit: 10,
DistanceMeasure: firestore.DistanceMeasureEuclidean,
VectorType: firebase.Vector64,
},
},
}
```

### Initialize Firebase

To initialize Firebase with the configuration, call the `Init` function. This ensures that the Firebase App is only initialized once:

```go
ctx := context.Background()
err := firebase.Init(ctx, firebaseConfig)
if err != nil {
log.Fatalf("Error initializing Firebase: %v", err)
}
```

Once initialized, the Firebase app can be accessed using the `App` function:

```go
app, err := firebase.App(ctx)
if err != nil {
log.Fatalf("Error getting Firebase app: %v", err)
}
```

### Firestore Retriever

The Firebase plugin provides a Firestore retriever that can be used to query documents in a Firestore collection based on vector similarity.

1. **Options Configuration**:
You need to configure `RetrieverOptions`, which include:

- **Client**: The Firestore client.
- **Collection**: The Firestore collection you want to query.
- **Embedder**: The AI embedder to convert documents into embeddings.
- **VectorField**: The Firestore field containing the vector embeddings.
- **ContentField**: The field containing the text of the document.
- **MetadataFields**: A list of fields to include in the document metadata.

```go
retrieverOptions := firebase.RetrieverOptions{
Name: "example-retriever",
Client: firestoreClient,
Collection: collectionName,
Embedder: embedder,
VectorField: "embedding",
ContentField: "text",
MetadataFields: []string{"metadata"},
Limit: 10,
DistanceMeasure: firestore.DistanceMeasureEuclidean,
VectorType: firebase.Vector64,
}
```

2. **Define the Retriever**:

```go
retriever, err := firebase.DefineFirestoreRetriever(retrieverOptions)
if err != nil {
log.Fatalf("Error defining Firestore retriever: %v", err)
}
```

3. **Use the Retriever**:

To perform a retrieval based on a query document:

```go
req := &ai.RetrieverRequest{
Document: ai.DocumentFromText("Query text", nil),
}

resp, err := retriever.Retrieve(ctx, req)
if err != nil {
log.Fatalf("Error retrieving documents: %v", err)
}

for _, doc := range resp.Documents {
log.Printf("Retrieved document: %s", doc.Content[0].Text)
}
```

### Firebase Authentication

The Firebase plugin integrates Firebase Authentication to provide authorization and access control in Genkit flows.

1. **Creating an Auth Object**:
Use the `NewAuth` function to create an auth object, specifying whether authentication is required and the policy for checking the context:

```go
auth, err := firebase.NewAuth(ctx, nil, true)
if err != nil {
log.Fatalf("Error initializing Firebase Auth: %v", err)
}
```

2. **Providing Authentication Context**:
To use authentication, the `ProvideAuthContext` function extracts the authentication header from a request, verifies the token, and provides the auth context:

```go
ctx, err := auth.ProvideAuthContext(ctx, "Bearer your-id-token")
if err != nil {
log.Fatalf("Error providing auth context: %v", err)
}
```

3. **Checking Authorization Policy**:
The `CheckAuthPolicy` function ensures that the current auth context satisfies any policies you’ve defined for your flow:

```go
err := auth.CheckAuthPolicy(ctx, inputData)
if err != nil {
log.Fatalf("Authorization check failed: %v", err)
}
```

## Local Testing

When testing flows locally, ensure that the Google Cloud credentials are available to the Firebase SDK. Use the following command to authenticate:

```bash
gcloud auth application-default login
```

This will provide your local environment with the necessary credentials to interact with Firebase services.

## Conclusion

The Firebase Genkit Plugin simplifies the integration of Firebase services, including Firestore and Firebase Authentication, into your Genkit flows. With features like Firestore vector queries and flow-level authentication, it provides powerful tools for building intelligent, secure applications.
Loading
Loading