Skip to content
goloopPublic

About

Go client for a local or remote Ollama server on the goloop/ai interface

Resources

Code of conduct

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

20 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

deps.dev License License Stay with Ukraine

ollama

ollama is a Go client for a local or remote Ollama server. It implements the github.com/goloop/ai interface, so it looks and works like every other goloop AI provider, and exposes Ollama's native endpoints on top.

Features

  • Chat: Generate for a single response, Stream for token-by-token output through iter.Seq2.
  • Tool use (function calling) and image input.
  • Native ChatCompletion and ChatStream over /api/chat.
  • Embeddings, the installed-model list and per-model details (Show).
  • Retries on 429 and 5xx with backoff; normalized, typed API errors.
  • Depends only on github.com/goloop/ai and the standard library.
  • Structured output: ai.Format maps onto the server's format field ("json" or a schema); read the reply with resp.JSON(&v).
  • Hosted capabilities: ai.Request.Hosted is refused with ai.ErrNoHosted, because a local model server has no search to run.

Installation

go get github.com/goloop/ollama

Quick start

package main

import (
	"context"
	"fmt"

	"github.com/goloop/ai"
	"github.com/goloop/ollama"
)

func main() {
	c := ollama.New("") // local server on http://localhost:11434

	resp, err := c.Generate(context.Background(), &ai.Request{
		Model:    ollama.ModelLlama32,
		Messages: []ai.Message{ai.UserText("Say hello in one word.")},
	})
	if err != nil {
		panic(err)
	}
	fmt.Println(resp.Text())
}

Remote server

c := ollama.New(apiKey, ollama.WithBaseURL("https://ollama.example.com"))

The API key is optional; it is sent as a bearer token when set, for authenticated proxies in front of a server.

Streaming

Ollama streams newline-delimited JSON rather than Server-Sent Events; Stream hides that difference and yields the same ai.Chunk values as every other provider.

for chunk, err := range c.Stream(ctx, req) {
	if err != nil {
		break
	}
	fmt.Print(chunk.Text)
}

Embeddings and models

vecs, err := c.Embed(ctx, ollama.ModelLlama32, "hello", "world")
models, err := c.Models(ctx) // what is installed locally
info, err := c.Show(ctx, ollama.ModelLlama32) // template, params, capabilities

Documentation

Full reference: DOC.md (Ukrainian: DOC.UK.md).

Contributing

See CONTRIBUTING.md.

License

MIT - see LICENSE.

Release v1.1.4

Report malformed stream events and reject nil requests.

About

Go client for a local or remote Ollama server on the goloop/ai interface

Resources

Code of conduct

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages