inference

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Downloader

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

Downloader handles background downloading of models

func NewDownloader

func NewDownloader(modelsDir string) *Downloader

NewDownloader creates a new model downloader

func (*Downloader) DownloadModel

func (d *Downloader) DownloadModel(ctx context.Context, modelID string, url string) error

DownloadModel downloads a model from a URL

func (*Downloader) GetProgress

func (d *Downloader) GetProgress(modelID string) (float64, bool)

GetProgress returns the download progress for a model (0-1)

type GenOptions added in v0.8.0

type GenOptions struct {
	ModelID     string  `json:"modelId"`
	MaxTokens   int     `json:"max_tokens"`
	Temperature float32 `json:"temperature"`
}

GenOptions represents the parameters for a generation request

type InferenceProvider added in v0.8.0

type InferenceProvider interface {
	// Generate performs a full generation request to the provider
	Generate(ctx context.Context, prompt string, options GenOptions) (string, error)
	// TestConnection verifies that the provider is reachable and functional
	TestConnection(ctx context.Context) (string, error)
	// ListModels retrieves a list of available models from the provider
	ListModels(ctx context.Context) ([]string, error)
	// PullModel requests the provider to download a new model
	PullModel(ctx context.Context, modelID string) error
}

InferenceProvider defines the interface for external inference engines

type InferenceRequest

type InferenceRequest struct {
	ModelID     string  `json:"modelId"`
	Prompt      string  `json:"prompt"`
	Context     string  `json:"context"`
	MaxTokens   int     `json:"max_tokens"`
	Temperature float32 `json:"temperature"`
}

InferenceRequest represents a request to the Local SLM

type InferenceResponse

type InferenceResponse struct {
	Text  string `json:"text"`
	Error string `json:"error,omitempty"`
}

InferenceResponse represents the distilled output from Local SLM

type InferenceService

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

InferenceService manages the external inference execution

func NewInferenceService

func NewInferenceService(provider InferenceProvider) *InferenceService

NewInferenceService creates a new inference service

func (*InferenceService) Execute

Execute performs inference using the configured provider

type LMStudioProvider added in v0.8.0

type LMStudioProvider struct {
	BaseURL string
	Client  *http.Client
}

LMStudioProvider implements InferenceProvider for LM Studio Native API (/api/v1)

func NewLMStudioProvider added in v0.8.0

func NewLMStudioProvider(baseURL string) *LMStudioProvider

NewLMStudioProvider creates a new LM Studio native provider

func (*LMStudioProvider) Generate added in v0.8.0

func (p *LMStudioProvider) Generate(ctx context.Context, prompt string, options GenOptions) (string, error)

func (*LMStudioProvider) ListModels added in v0.8.0

func (p *LMStudioProvider) ListModels(ctx context.Context) ([]string, error)

func (*LMStudioProvider) PullModel added in v0.8.0

func (p *LMStudioProvider) PullModel(ctx context.Context, modelID string) error

func (*LMStudioProvider) TestConnection added in v0.8.0

func (p *LMStudioProvider) TestConnection(ctx context.Context) (string, error)

type ModelInfo

type ModelInfo struct {
	ID          string `json:"id"`
	Name        string `json:"name"`
	Size        int64  `json:"size"`
	Path        string `json:"path"`
	Downloaded  bool   `json:"downloaded"`
	DownloadURL string `json:"downloadUrl"`
	Description string `json:"description"`
	LastUsed    string `json:"lastUsed"`
}

ModelInfo represents metadata about a local model

type OllamaProvider added in v0.8.0

type OllamaProvider struct {
	BaseURL string
	Client  *http.Client
}

OllamaProvider implements InferenceProvider for Ollama native API

func NewOllamaProvider added in v0.8.0

func NewOllamaProvider(baseURL string) *OllamaProvider

NewOllamaProvider creates a new Ollama provider

func (*OllamaProvider) Generate added in v0.8.0

func (p *OllamaProvider) Generate(ctx context.Context, prompt string, options GenOptions) (string, error)

func (*OllamaProvider) ListModels added in v0.8.0

func (p *OllamaProvider) ListModels(ctx context.Context) ([]string, error)

func (*OllamaProvider) PullModel added in v0.8.0

func (p *OllamaProvider) PullModel(ctx context.Context, modelID string) error

func (*OllamaProvider) TestConnection added in v0.8.0

func (p *OllamaProvider) TestConnection(ctx context.Context) (string, error)

type OpenAIProvider added in v0.8.0

type OpenAIProvider struct {
	BaseURL string
	Client  *http.Client
}

OpenAIProvider implements InferenceProvider for OpenAI-compatible APIs

func NewOpenAIProvider added in v0.8.0

func NewOpenAIProvider(baseURL string) *OpenAIProvider

NewOpenAIProvider creates a new OpenAI compatible provider

func (*OpenAIProvider) Generate added in v0.8.0

func (p *OpenAIProvider) Generate(ctx context.Context, prompt string, options GenOptions) (string, error)

func (*OpenAIProvider) ListModels added in v0.8.0

func (p *OpenAIProvider) ListModels(ctx context.Context) ([]string, error)

func (*OpenAIProvider) PullModel added in v0.8.0

func (p *OpenAIProvider) PullModel(ctx context.Context, modelID string) error

func (*OpenAIProvider) TestConnection added in v0.8.0

func (p *OpenAIProvider) TestConnection(ctx context.Context) (string, error)

type WriteCounter

type WriteCounter struct {
	Total      int64
	Downloaded int64
	OnProgress func(float64)
}

WriteCounter counts the number of bytes written and updates progress

func (*WriteCounter) Write

func (wc *WriteCounter) Write(p []byte) (int, error)

Jump to

Keyboard shortcuts

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