Skip to content

nudibranches-tech/genkit-mistral

 
 

Repository files navigation

genkit-mistral ✨

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.

Go Reference License

Quick start 🚀

Install (Genkit + this plugin):

go get github.com/firebase/genkit/go
go get github.com/thomas-marquis/genkit-mistral

Usage

See 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.

Basit text generation

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())
}

Text 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),
		),
	)

	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)
}

Output format constrained

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)
}

Models and embeddings 🧠

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>'

Useful resources 📚

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

Contributing 🤝

Contributions are welcome! Please open an issue or a PR.

See CONTRIBUTING.md for more details.

About

Genkit mistral plugin

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Go 99.3%
  • Shell 0.7%