1package ollama
 2
 3import (
 4	"os/exec"
 5	"sync"
 6)
 7
 8// OllamaModel represents a model returned by Ollama's API
 9type OllamaModel struct {
10	Name       string `json:"name"`
11	Model      string `json:"model"`
12	Size       int64  `json:"size"`
13	ModifiedAt string `json:"modified_at"`
14	Digest     string `json:"digest"`
15	Details    struct {
16		ParentModel       string   `json:"parent_model"`
17		Format            string   `json:"format"`
18		Family            string   `json:"family"`
19		Families          []string `json:"families"`
20		ParameterSize     string   `json:"parameter_size"`
21		QuantizationLevel string   `json:"quantization_level"`
22	} `json:"details"`
23}
24
25// OllamaTagsResponse represents the response from Ollama's /api/tags endpoint
26type OllamaTagsResponse struct {
27	Models []OllamaModel `json:"models"`
28}
29
30// OllamaRunningModel represents a model that is currently loaded in memory
31type OllamaRunningModel struct {
32	Name    string `json:"name"`
33	Model   string `json:"model"`
34	Size    int64  `json:"size"`
35	Digest  string `json:"digest"`
36	Details struct {
37		ParentModel       string   `json:"parent_model"`
38		Format            string   `json:"format"`
39		Family            string   `json:"family"`
40		Families          []string `json:"families"`
41		ParameterSize     string   `json:"parameter_size"`
42		QuantizationLevel string   `json:"quantization_level"`
43	} `json:"details"`
44	ExpiresAt string `json:"expires_at"`
45	SizeVRAM  int64  `json:"size_vram"`
46}
47
48// OllamaRunningModelsResponse represents the response from Ollama's /api/ps endpoint
49type OllamaRunningModelsResponse struct {
50	Models []OllamaRunningModel `json:"models"`
51}
52
53// ProcessManager manages Ollama processes started by Crush
54type ProcessManager struct {
55	mu                 sync.RWMutex
56	processes          map[string]*exec.Cmd
57	ollamaServer       *exec.Cmd // The main Ollama server process
58	setupOnce          sync.Once
59	crushStartedOllama bool // Track if Crush started the Ollama service
60}