Module: Legion::Extensions::Ollama::Runners::Models

Extended by:
Helpers::Client
Includes:
Helpers::Lex
Included in:
Client
Defined in:
lib/legion/extensions/ollama/runners/models.rb

Constant Summary

Constants included from Helpers::Client

Helpers::Client::DEFAULT_HOST

Instance Method Summary collapse

Methods included from Helpers::Client

client, streaming_client

Instance Method Details

#copy_model(source:, destination:) ⇒ Object



31
32
33
34
35
# File 'lib/legion/extensions/ollama/runners/models.rb', line 31

def copy_model(source:, destination:, **)
  body = { source: source, destination: destination }
  response = Helpers::Errors.with_retry { client(**).post('/api/copy', body) }
  { result: response.status == 200, status: response.status }
end

#create_model(model:, from: nil, files: nil, system: nil, stream: false, quantize: nil) ⇒ Object



13
14
15
16
17
18
# File 'lib/legion/extensions/ollama/runners/models.rb', line 13

def create_model(model:, from: nil, files: nil, system: nil, stream: false, quantize: nil, **)
  body = { model: model, from: from, files: files, system: system,
           stream: stream, quantize: quantize }.compact
  response = Helpers::Errors.with_retry { client(**).post('/api/create', body) }
  { result: response.body, status: response.status }
end

#delete_model(model:) ⇒ Object



37
38
39
40
41
42
43
44
45
# File 'lib/legion/extensions/ollama/runners/models.rb', line 37

def delete_model(model:, **)
  body = { model: model }
  response = Helpers::Errors.with_retry do
    client(**).delete('/api/delete') do |req|
      req.body = body
    end
  end
  { result: response.status == 200, status: response.status }
end

#list_modelsObject



20
21
22
23
# File 'lib/legion/extensions/ollama/runners/models.rb', line 20

def list_models(**)
  response = Helpers::Errors.with_retry { client(**).get('/api/tags') }
  { result: response.body, status: response.status }
end

#list_runningObject



59
60
61
62
# File 'lib/legion/extensions/ollama/runners/models.rb', line 59

def list_running(**)
  response = Helpers::Errors.with_retry { client(**).get('/api/ps') }
  { result: response.body, status: response.status }
end

#pull_model(model:, insecure: nil, stream: false) ⇒ Object



47
48
49
50
51
# File 'lib/legion/extensions/ollama/runners/models.rb', line 47

def pull_model(model:, insecure: nil, stream: false, **)
  body = { model: model, insecure: insecure, stream: stream }.compact
  response = Helpers::Errors.with_retry { client(**).post('/api/pull', body) }
  { result: response.body, status: response.status }
end

#push_model(model:, insecure: nil, stream: false) ⇒ Object



53
54
55
56
57
# File 'lib/legion/extensions/ollama/runners/models.rb', line 53

def push_model(model:, insecure: nil, stream: false, **)
  body = { model: model, insecure: insecure, stream: stream }.compact
  response = Helpers::Errors.with_retry { client(**).post('/api/push', body) }
  { result: response.body, status: response.status }
end

#show_model(model:, verbose: nil) ⇒ Object



25
26
27
28
29
# File 'lib/legion/extensions/ollama/runners/models.rb', line 25

def show_model(model:, verbose: nil, **)
  body = { model: model, verbose: verbose }.compact
  response = Helpers::Errors.with_retry { client(**).post('/api/show', body) }
  { result: response.body, status: response.status }
end