Help us shape the future of Go! Take the 2026 Go Developer Survey

provider

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: EUPL-1.2 Imports: 15 Imported by: 0

Documentation

Overview

Package provider talks to LLM backends over HTTP.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrAuth means the provider rejected the credentials (401, 403).
	ErrAuth = errors.New("authentication rejected by the provider")
	// ErrContextLength means the prompt exceeds the model context window.
	ErrContextLength = errors.New("context too long for the model")
	// ErrIncomplete means the stream ended without a completion marker.
	ErrIncomplete = errors.New("stream interrupted before the end of the response")
	// ErrUnavailable means the provider stayed unreachable after retries.
	ErrUnavailable = errors.New("provider unavailable")
)
View Source
var ErrModelNotFound = errors.New("model not found on the server")

ErrModelNotFound : le modèle demandé n'est pas servi.

View Source
var ErrNoModel = errors.New("no usable model")

ErrNoModel : le serveur ne sert aucun modèle utilisable.

Functions

func NoProxyDetectClient added in v0.7.0

func NoProxyDetectClient() *http.Client

NoProxyDetectClient est detectClient(nil) sans proxy d'environnement (HTTP_PROXY, HTTPS_PROXY) : profil strict-local, ou secnumcloud avec un fournisseur local. http.DefaultTransport n'est pas modifié.

Types

type Detected added in v0.2.0

type Detected struct {
	Model         string
	ContextWindow int // 0 : inconnue
	// ModelWindow est la fenêtre maximale du modèle (Ollama), 0 si inconnue.
	ModelWindow int
}

Detected décrit ce qu'un serveur local (Ollama, vLLM) sert réellement : le modèle et la fenêtre de contexte appliquée par le serveur, qui peut être bien plus petite que celle du modèle (Ollama : 4096 jetons par défaut sur une machine modeste).

func DetectOllama added in v0.2.0

func DetectOllama(ctx context.Context, c *http.Client, baseURL, model string) (Detected, error)

DetectOllama interroge le serveur Ollama de baseURL. Sans model, il choisit le modèle modifié le plus récemment parmi ceux qui acceptent les appels d'outils. La fenêtre est celle du modèle chargé (/api/ps) : le modèle est donc chargé en mémoire, ce que le premier appel ferait de toute façon.

func DetectVLLM added in v0.2.0

func DetectVLLM(ctx context.Context, c *http.Client, baseURL, model string) (Detected, error)

DetectVLLM interroge GET /models du serveur vLLM. Sans model, le serveur doit servir un seul modèle. La fenêtre est max_model_len.

type OpenAICompat

type OpenAICompat struct {
	// contains filtered or unexported fields
}

OpenAICompat implements Provider for OpenAI-compatible chat completions.

func NewOpenAICompat

func NewOpenAICompat(info llm.ProviderInfo, apiKey string, opts ...Option) *OpenAICompat

NewOpenAICompat builds a provider for info.BaseURL.

func (*OpenAICompat) Info

func (o *OpenAICompat) Info() llm.ProviderInfo

Info returns the provider description.

func (*OpenAICompat) Stream

func (o *OpenAICompat) Stream(ctx context.Context, req llm.Request) (<-chan llm.Chunk, error)

Stream starts a streamed completion.

type Option

type Option func(*OpenAICompat)

Option configures an OpenAICompat provider.

func WithHTTPClient

func WithHTTPClient(c *http.Client) Option

WithHTTPClient sets the HTTP client.

func WithSleep

func WithSleep(f func(context.Context, time.Duration) error) Option

WithSleep overrides the wait function used between retries. It must return ctx.Err() as soon as ctx is cancelled.

func WithoutProxy added in v0.7.0

func WithoutProxy() Option

WithoutProxy makes the client ignore HTTP_PROXY/HTTPS_PROXY (strict-local profile, or secnumcloud with a local provider): a private address accepted by the profile must not leave the machine through an environment proxy.

type Provider

type Provider interface {
	Info() llm.ProviderInfo
	Stream(ctx context.Context, req llm.Request) (<-chan llm.Chunk, error)
}

Provider streams completions from an LLM backend.

Jump to

Keyboard shortcuts

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