Class: Regent::LLM::Ollama
Constant Summary collapse
- DEFAULT_HOST =
Default host for Ollama API.
"http://localhost:11434"
Instance Attribute Summary collapse
-
#model ⇒ Object
readonly
Returns the value of attribute model.
Instance Method Summary collapse
-
#initialize(model:, host: nil, **options) ⇒ Ollama
constructor
A new instance of Ollama.
- #invoke(messages, **args) ⇒ Object
- #parse_error(error) ⇒ Object
Methods included from Concerns::Dependable
Constructor Details
#initialize(model:, host: nil, **options) ⇒ Ollama
Returns a new instance of Ollama.
9 10 11 12 13 |
# File 'lib/regent/llm/ollama.rb', line 9 def initialize(model:, host: nil, **) @model = model @host = host || DEFAULT_HOST = end |
Instance Attribute Details
#model ⇒ Object (readonly)
Returns the value of attribute model.
15 16 17 |
# File 'lib/regent/llm/ollama.rb', line 15 def model @model end |
Instance Method Details
#invoke(messages, **args) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/regent/llm/ollama.rb', line 17 def invoke(, **args) response = client.post("/api/chat", { model: model, messages: , stream: false }) if response.status == 200 result( model: response.body.dig("model"), content: response.body.dig("message", "content").strip, input_tokens: nil, output_tokens: nil ) else raise ApiError, response.body.dig("error") end end |
#parse_error(error) ⇒ Object
36 37 38 |
# File 'lib/regent/llm/ollama.rb', line 36 def parse_error(error) error. end |