Class: Clarinet::Models
- Inherits:
-
Object
- Object
- Clarinet::Models
- Extended by:
- Forwardable
- Defined in:
- lib/clarinet/models.rb
Instance Attribute Summary collapse
-
#raw_data ⇒ Hash
readonly
Raw API data used to construct this instance.
Instance Method Summary collapse
- #[] ⇒ Clarinet::Model
- #each ⇒ Object
- #find ⇒ Object
- #first ⇒ Object
-
#get(id) ⇒ Clarinet::Model
Returns a model specified by ID.
-
#init_model(model) ⇒ Clarinet::Model
Returns a Model instance given model id or name.
- #last ⇒ Object
-
#list(options = { page: 1, per_page: 20 }) ⇒ Clarinet::Models
Return all the models.
- #map ⇒ Object
-
#predict(model, inputs) ⇒ Hash
Predict using a specific model.
-
#search(name, type = nil) ⇒ Clarinet::Models
Search for models by name or type.
- #select ⇒ Object
Instance Attribute Details
#raw_data ⇒ Hash (readonly)
Returns Raw API data used to construct this instance.
27 28 29 |
# File 'lib/clarinet/models.rb', line 27 def raw_data @raw_data end |
Instance Method Details
#[] ⇒ Clarinet::Model
24 |
# File 'lib/clarinet/models.rb', line 24 delegate [:[], :each, :map, :find, :first, :last, :select, :reject, :size] => :@models |
#each ⇒ Object
24 |
# File 'lib/clarinet/models.rb', line 24 delegate [:[], :each, :map, :find, :first, :last, :select, :reject, :size] => :@models |
#find ⇒ Object
24 |
# File 'lib/clarinet/models.rb', line 24 delegate [:[], :each, :map, :find, :first, :last, :select, :reject, :size] => :@models |
#first ⇒ Object
24 |
# File 'lib/clarinet/models.rb', line 24 delegate [:[], :each, :map, :find, :first, :last, :select, :reject, :size] => :@models |
#get(id) ⇒ Clarinet::Model
Returns a model specified by ID
86 87 88 89 |
# File 'lib/clarinet/models.rb', line 86 def get(id) data = @app.client.model id Clarinet::Model.new @app, data[:model] end |
#init_model(model) ⇒ Clarinet::Model
Returns a Model instance given model id or name. It will call search if name is given.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/clarinet/models.rb', line 48 def init_model(model) model_data = {} model_data[:id] = model if model.is_a? String model_data = model if model.is_a? Hash model_data = model.raw_data if model.is_a? Clarinet::Model return Clarinet::Model.new @app, model_data if model_data[:id] search_results = search model_data[:name], model_data[:type] return search_results.find { |result| result.model_version.id == model_data[:version] }.first if model_data[:version] search_results.first end |
#last ⇒ Object
24 |
# File 'lib/clarinet/models.rb', line 24 delegate [:[], :each, :map, :find, :first, :last, :select, :reject, :size] => :@models |
#list(options = { page: 1, per_page: 20 }) ⇒ Clarinet::Models
Return all the models
78 79 80 81 |
# File 'lib/clarinet/models.rb', line 78 def list( = { page: 1, per_page: 20 }) data = @app.client.models Clarinet::Models.new @app, data[:models] end |
#map ⇒ Object
24 |
# File 'lib/clarinet/models.rb', line 24 delegate [:[], :each, :map, :find, :first, :last, :select, :reject, :size] => :@models |
#predict(model, inputs) ⇒ Hash
Predict using a specific model
69 70 71 |
# File 'lib/clarinet/models.rb', line 69 def predict(model, inputs) init_model(model).predict(inputs) end |
#search(name, type = nil) ⇒ Clarinet::Models
Search for models by name or type
95 96 97 98 99 100 101 102 103 |
# File 'lib/clarinet/models.rb', line 95 def search(name, type = nil) query = { name: name, type: type } data = @app.client.models_search query Clarinet::Models.new @app, data[:models] end |
#select ⇒ Object
24 |
# File 'lib/clarinet/models.rb', line 24 delegate [:[], :each, :map, :find, :first, :last, :select, :reject, :size] => :@models |