Easy Ollama package for Golang
go get -u github.com/jonathanhecl/gollama
package main
import (
"fmt"
"github.com/jonathanhecl/gollama"
)
func main() {
g := gollama.New("llama3.2")
g.Verbose = true
if err := g.PullIfMissing(); err != nil {
fmt.Println("Error:", err)
return
}
prompt := "what is the capital of Argentina?"
type Capital struct {
Capital string `required:"true"`
}
option, _ := gollama.StructToStructuredFormat(Capital{})
fmt.Printf("Option: %+v\n", option)
output, err := g.Chat(prompt, option)
if err != nil {
fmt.Println("Error:", err)
return
}
fmt.Printf("\n%s\n", output.Content)
}
- Support Vision models
- Support Tools models
- Support Structured format
- Downloads model if missing
- Chat with model
- Generates embeddings with model
- Get model details
New(model string) *Gollama
- Create a new GollamaNewWithConfig(config Gollama) *Gollama
- Create a new Gollama with a pre-populated configChat(prompt string, ...ChatOption) (*gollama.ChatOutput, error)
- Generate a responseEmbedding(prompt string) ([]float64, error)
- Generate embeddingsListModels() ([]ModelInfo, error)
- List models available on ollamaHasModel(model string) (bool, error)
- Check if model is availableModelSize(model string) (int, error)
- Get model size from ollamaPullModel(model string) error
- Pull modelPullIfMissing(model ...string) error
- Pull model if missingGetDetails(model ...string) ([]ModelDetails, error)
- Get model details from ollamaVersion() (string, error)
- Get ollama versionStructToStructuredFormat(interface{}) (StructuredFormat, error)
- Converts a Go struct to a Gollama structured formatCosenoSimilarity(vector1, vector2 []float64) float64
- Calculates the cosine similarity between two vectors