ollama

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 5, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package ollama is a reference backend emulator for Ollama's API surface. It serves GET /api/version, GET /v1/models, POST /api/show, POST /v1/chat/completions, and POST /v1/responses with JSON or SSE bodies compatible with OpenAI-compatible clients.

Index

Constants

View Source
const ChatStreamWithUsageSSE = "data: {\"id\":\"chatcmpl-ollama-refbackend-stream\",\"object\":\"chat.completion.chunk\",\"created\":1715620000,\"model\":\"llama3:latest\",\"choices\":[{\"index\":0,\"delta\":{\"content\":\"ollama-stream-ok\"},\"finish_reason\":null}]}\n\n" +
	"data: {\"id\":\"chatcmpl-ollama-refbackend-stream\",\"object\":\"chat.completion.chunk\",\"created\":1715620000,\"model\":\"llama3:latest\",\"choices\":[{\"index\":0,\"delta\":{},\"finish_reason\":\"stop\"}]}\n\n" +
	"data: {\"id\":\"chatcmpl-ollama-refbackend-stream\",\"object\":\"chat.completion.chunk\",\"created\":1715620000,\"model\":\"llama3:latest\",\"choices\":[],\"usage\":{\"prompt_tokens\":3,\"completion_tokens\":7,\"total_tokens\":10}}\n\n" +
	"data: [DONE]\n\n"
View Source
const DefaultChatNonStreamJSON = `` /* 302-byte string literal not displayed */
View Source
const DefaultChatStreamSSE = "data: {\"id\":\"chatcmpl-ollama-refbackend-stream\",\"object\":\"chat.completion.chunk\",\"created\":1715620000,\"model\":\"llama3:latest\",\"choices\":[{\"index\":0,\"delta\":{\"content\":\"ollama-stream-ok\"},\"finish_reason\":null}]}\n\n" +
	"data: [DONE]\n\n"
View Source
const DefaultResponsesNonStreamJSON = `` /* 425-byte string literal not displayed */
View Source
const DefaultResponsesStreamSSE = "event: response.completed\n" +
	"data: {\"type\":\"response.completed\",\"sequence_number\":1,\"response\":{\"id\":\"resp_ollama_refbackend_stream\",\"object\":\"response\",\"created_at\":1715620000,\"status\":\"completed\",\"model\":\"llama3:latest\",\"output\":[{\"type\":\"message\",\"id\":\"m1\",\"status\":\"completed\",\"role\":\"assistant\",\"content\":[{\"type\":\"output_text\",\"text\":\"ollama-stream-ok\"}]}],\"usage\":{\"input_tokens\":3,\"output_tokens\":7,\"total_tokens\":10}}}\n\n" +
	"data: [DONE]\n\n"

Variables

This section is empty.

Functions

func NewHandler

func NewHandler(cfg Config) http.Handler

NewHandler returns an http.Handler that emulates Ollama endpoints.

Types

type Config

type Config struct {
	Version      string
	LocalModels  []string
	CloudModels  []string
	Capabilities map[string][]string

	ResponsesSupported         bool
	ResponsesUnsupportedStatus int

	RequireBearer          bool
	OnAuthorizedCredential func(secret string)
	ForcedHTTPStatus       int
	ForcedRetryAfter       string
	ForcedErrorJSON        string
	OnRequest              func(r *http.Request, body []byte)
	OnRequestBody          func(body []byte)

	ChatNonStreamJSON      string
	ChatStreamSSE          string
	ResponsesNonStreamJSON string
	ResponsesStreamSSE     string
}

Config tunes the emulator handler.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL