# genkit




[](https://goreportcard.com/report/github.com/firebase/genkit)
[](https://pkg.go.dev/github.com/firebase/genkit)
> library for building generative ai applications with llms
## table of contents
- [install](#install)
- [usage](#usage)
- [api](#api)
- [contributing](#contributing)
- [license](#license)
## install
```bash
go get github.com/firebase/genkitpackage main
import (
"context"
"fmt"
"log"
"github.com/firebase/genkit/go/ai"
"github.com/firebase/genkit/go/genkit"
)
func main() {
ctx := context.Background()
// initialize genkit with a model
model := ai.DefineModel("my-model", "openai/gpt-4", nil)
// create a simple prompt flow
flow := genkit.DefineFlow("summarize", func(ctx context.Context, input string) (string, error) {
resp, err := model.Generate(ctx, ai.NewRequest(
&ai.GenerateRequest{
Prompt: fmt.Sprintf("Summarize this text: %s", input),
},
))
if err != nil {
return "", err
}
return resp.Text(), nil
})
// run the flow
result, err := flow.Run(ctx, "Your long text here...")
if err != nil {
log.Fatal(err)
}
fmt.Println(result)
}| function | description |
|---|---|
genkit.DefineFlow |
define a flow with inputs, outputs, and generation logic |
genkit.DefinePrompt |
create reusable prompt templates |
ai.DefineModel |
register an llm or custom model |
ai.Generate |
call a model with a prompt |
flows are the main abstraction for organizing ai logic. they handle streaming, tracing, and state management.
flow := genkit.DefineFlow("my-flow", func(ctx context.Context, input MyInput) (MyOutput, error) {
// your logic here
})genkit supports multiple model providers:
- openai (gpt-4, gpt-3.5-turbo)
- google ai (gemini)
- anthropic (claude)
- custom models
model := ai.DefineModel("provider", "model-name", &ai.ModelConfig{
Temperature: 0.7,
MaxTokens: 1000,
})create structured prompts with variable substitution:
prompt := genkit.DefinePrompt("translate", "Translate {{text}} to {{language}}")
result, err := prompt.Generate(ctx, map[string]any{
"text": "hello",
"language": "spanish",
})built-in tracing for debugging and monitoring:
trace := genkit.StartTrace(ctx, "operation-name")
defer trace.End()prs welcome. open an issue first for big changes.
run tests with:
go test ./...Apache 2.0