Module: LLM::Huggingface
- Defined in:
- lib/scout/llm/backends/huggingface.rb
Class Method Summary collapse
- .ask(question, options = {}, &block) ⇒ Object
- .embed(text, options = {}) ⇒ Object
- .model(model_options) ⇒ Object
Class Method Details
.ask(question, options = {}, &block) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/scout/llm/backends/huggingface.rb', line 16 def self.ask(question, = {}, &block) = IndiferentHash.pull_keys , :model = IndiferentHash.add_defaults , :task => "CausalLM" model = self.model = LLM.(question) system = [] prompt = [] .each do || role, content = .values_at :role, :content if role == 'system' system << content else prompt << content end end parameters = .merge(messages: ) Log.debug "Calling client with parameters: #{Log.fingerprint parameters}" model.eval() end |
.embed(text, options = {}) ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/scout/llm/backends/huggingface.rb', line 41 def self.(text, = {}) = IndiferentHash.pull_keys , :model = IndiferentHash.add_defaults , :task => "Embedding" model = self.model (Array === text) ? model.eval_list(text) : model.eval(text) end |
.model(model_options) ⇒ Object
6 7 8 9 10 11 12 13 14 |
# File 'lib/scout/llm/backends/huggingface.rb', line 6 def self.model() require 'scout/model/python/huggingface' require 'scout/model/python/huggingface/causal' model, task, checkpoint, dir = IndiferentHash. , :model, :task, :checkpoint, :dir model ||= Scout::Config.get(:model, :huggingface, env: 'HUGGINGFACE_MODEL,HF_MODEL') CausalModel.new model, dir, end |