Skip to content
Merged
Changes from all commits
Commits
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
59 changes: 39 additions & 20 deletions src/content/docs/docs/integrations/ollama.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -196,16 +196,25 @@ initializer, specifying the address of your Ollama server and the response timeo
(defaulted to 30 seconds):

```go
import "github.com/firebase/genkit/go/plugins/ollama"
```
import (
"context"
"log"

```go
g := genkit.Init(context.Background(),
genkit.WithPlugins(&ollama.Ollama{
ServerAddress: "http://127.0.0.1:11434",
Timeout: 60, // Optional field, adjust accordingly
}),
)
"github.com/firebase/genkit/go/ai"
"github.com/firebase/genkit/go/genkit"
"github.com/firebase/genkit/go/plugins/ollama"
)

func main() {
ctx := context.Background()

ollamaPlugin := &ollama.Ollama{
ServerAddress: "http://127.0.0.1:11434",
Timeout: 60, // Optional field, adjust accordingly
}

g := genkit.Init(ctx, genkit.WithPlugins(ollamaPlugin))
}
```

## Usage
Expand All @@ -215,22 +224,28 @@ model you installed and want to use. For example, if you installed Gemma 3:

```go
model := ollama.DefineModel(
ollama.ModelDefinition{
Name: "gemma3",
Type: "chat", // "chat" or "generate"
},
&ai.ModelInfo{
Multiturn: true,
SystemRole: true,
Tools: false,
Media: false,
ollama.ModelDefinition{
Name: "gemma3",
Type: "chat", // "chat" or "generate"
},
&ai.ModelOptions{
Supports: &ai.ModelSupports{
Multiturn: true,
SystemRole: true,
Tools: false,
Media: false,
},
},
)
```

Then, you can use the model reference to send requests to your Ollama server:
```go
resp, err := genkit.Generate(ctx, g, ai.WithModel(model), ai.WithPrompt("Tell me a joke."))
resp, err := genkit.Generate(ctx,
g,
ai.WithModel(model),
ai.WithPrompt("Tell me a joke."),
)
if err != nil {
return err
}
Expand All @@ -240,7 +255,11 @@ log.Println(resp.Text())

Or you can refer to the model by its name:
```go
resp, err := genkit.Generate(ctx, g, ai.WithModelName("ollama/gemma3:latest"), ai.WithPrompt("Tell me a joke."))
resp, err := genkit.Generate(ctx,
g,
ai.WithModelName("ollama/gemma3:latest"),
ai.WithPrompt("Tell me a joke."),
)
if err != nil {
return err
}
Expand Down