Enables Mistral AI support for Firebase Genkit (Go SDK). Build agents and apps with Genkit while calling Mistral models and embeddings with a clean, typed Go API.
Install (Genkit + this plugin):
go get github.com/firebase/genkit/go
go get github.com/thomas-marquis/genkit-mistralSee the full API and more examples in the Go reference: https://pkg.go.dev/github.com/thomas-marquis/genkit-mistral
Check the Genkit's documentation for more insights.
package main
import (
"context"
"fmt"
"os"
"github.com/firebase/genkit/go/genkit"
"github.com/firebase/genkit/go/ai"
"github.com/thomas-marquis/genkit-mistral/mistral"
)
func main() {
mistralApiKey := os.Getenv("MISTRAL_API_KEY")
ctx := context.Background()
g := genkit.Init(ctx,
genkit.WithPlugins(
mistral.NewPlugin(mistralApiKey),
),
genkit.WithDefaultModel("mistral/mistral-small-latest"),
)
res, err := genkit.Generate(ctx, g,
ai.WithSystem("you are a helpful assistant"),
ai.WithPrompt("Tell me a joke"),
)
if err != nil {
panic(err)
}
fmt.Println(res.Text())
}package main
import (
"context"
"fmt"
"os"
"github.com/firebase/genkit/go/genkit"
"github.com/firebase/genkit/go/ai"
"github.com/thomas-marquis/genkit-mistral/mistral"
)
func main() {
mistralApiKey := os.Getenv("MISTRAL_API_KEY")
ctx := context.Background()
g := genkit.Init(ctx,
genkit.WithPlugins(
mistral.NewPlugin(mistralApiKey),
),
)
docToEmbed := ai.DocumentFromText("Is scribe a good situation?", nil)
res, err := genkit.Embed(ctx, g,
ai.WithDocs(docToEmbed),
ai.WithEmbedderName("mistral/mistral-embed"),
)
if err != nil {
panic(err)
}
fmt.Println(res.Embeddings[0].Embedding)
}package main
import (
"context"
"fmt"
"os"
"github.com/firebase/genkit/go/genkit"
"github.com/firebase/genkit/go/ai"
"github.com/thomas-marquis/genkit-mistral/mistral"
)
func main() {
mistralApiKey := os.Getenv("MISTRAL_API_KEY")
ctx := context.Background()
g := genkit.Init(ctx,
genkit.WithPlugins(
mistral.NewPlugin(mistralApiKey),
),
genkit.WithDefaultModel("mistral/mistral-small-latest"),
)
type expectedOutput struct {
JokeContent string `json:"joke_content"`
LolLevel int `json:"lol_level"`
}
res, err := genkit.Generate(ctx, g,
ai.WithSystem("you are a helpful assistant"),
ai.WithPrompt("Tell me a joke"),
ai.WithOutputType(expectedOutput{}),
)
if err != nil {
panic(err)
}
var joke expectedOutput
if err := res.Output(&joke); err != nil {
fmt.Printf("Failed to parse output: %s\n", err)
}
fmt.Printf("Is this \"%s\" really level %d???!!\n", joke.JokeContent, joke.LolLevel)
}You can find all tes mistral models with this command:
curl --request GET \
--url https://api.mistral.ai/v1/models \
--header 'Authorization: Bearer <your API token>'| Resource | For what? | Link(s) |
|---|---|---|
| Mistral AI | French AI provider | Website API documentation |
| Genkit | Agentic framework (Go, Node.js, Python) | Docs Go SDK |
| La Plateforme | Mistral's cloud platform for developers | Website Pricing |
Contributions are welcome! Please open an issue or a PR.
See CONTRIBUTING.md for more details.