types.go

 1package ollama
 2
 3import (
 4	"os/exec"
 5	"sync"
 6	"time"
 7)
 8
 9// Constants for configuration
10const (
11	DefaultBaseURL      = "http://localhost:11434"
12	DefaultTimeout      = 30 * time.Second
13	ServiceStartTimeout = 15 * time.Second
14	ModelLoadTimeout    = 60 * time.Second
15)
16
17// Model represents an Ollama model
18type Model struct {
19	Name       string    `json:"name"`
20	Model      string    `json:"model"`
21	Size       int64     `json:"size"`
22	Digest     string    `json:"digest"`
23	ModifiedAt time.Time `json:"modified_at"`
24	Details    struct {
25		ParentModel       string   `json:"parent_model"`
26		Format            string   `json:"format"`
27		Family            string   `json:"family"`
28		Families          []string `json:"families"`
29		ParameterSize     string   `json:"parameter_size"`
30		QuantizationLevel string   `json:"quantization_level"`
31	} `json:"details"`
32}
33
34// RunningModel represents a model currently loaded in memory
35type RunningModel struct {
36	Name      string    `json:"name"`
37	Model     string    `json:"model"`
38	Size      int64     `json:"size"`
39	Digest    string    `json:"digest"`
40	ExpiresAt time.Time `json:"expires_at"`
41	SizeVRAM  int64     `json:"size_vram"`
42	Details   struct {
43		ParentModel       string   `json:"parent_model"`
44		Format            string   `json:"format"`
45		Family            string   `json:"family"`
46		Families          []string `json:"families"`
47		ParameterSize     string   `json:"parameter_size"`
48		QuantizationLevel string   `json:"quantization_level"`
49	} `json:"details"`
50}
51
52// TagsResponse represents the response from /api/tags
53type TagsResponse struct {
54	Models []Model `json:"models"`
55}
56
57// ProcessStatusResponse represents the response from /api/ps
58type ProcessStatusResponse struct {
59	Models []RunningModel `json:"models"`
60}
61
62// GenerateRequest represents a request to /api/generate
63type GenerateRequest struct {
64	Model  string `json:"model"`
65	Prompt string `json:"prompt"`
66	Stream bool   `json:"stream"`
67}
68
69// ProcessManager manages Ollama processes started by Crush
70type ProcessManager struct {
71	mu                 sync.RWMutex
72	ollamaProcess      *exec.Cmd
73	crushStartedOllama bool
74	setupOnce          sync.Once
75}