Skip to content

2aronS/genkit

Repository files navigation

# genkit

![license](https://img.shields.io/badge/license-Apache%202.0-blue)
![status](https://img.shields.io/badge/status-active-brightgreen)
![go version](https://img.shields.io/badge/go-%3E%3D1.21-00ADD8)
![build](https://img.shields.io/badge/build-passing-brightgreen)
[![go report card](https://goreportcard.com/badge/github.com/firebase/genkit)](https://goreportcard.com/report/github.com/firebase/genkit)
[![godoc](https://img.shields.io/badge/godoc-reference-5272B4.svg)](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/genkit

usage

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

api

core functions

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

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

models

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

prompts

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

tracing

built-in tracing for debugging and monitoring:

trace := genkit.StartTrace(ctx, "operation-name")
defer trace.End()

contributing

prs welcome. open an issue first for big changes.

run tests with:

go test ./...

license

Apache 2.0

About

Library for building generative AI applications with LLMs

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages