Class: LLM::Ollama
- Defined in:
- lib/llm/providers/ollama.rb,
lib/llm/providers/ollama/models.rb,
lib/llm/providers/ollama/error_handler.rb,
lib/llm/providers/ollama/stream_parser.rb,
lib/llm/providers/ollama/request_adapter.rb,
lib/llm/providers/ollama/response_adapter.rb
Overview
The Ollama class implements a provider for Ollama – and the provider supports a wide range of models. It is straight forward to run on your own hardware, and there are a number of multi-modal models that can process both images and text.
Defined Under Namespace
Classes: Models
Constant Summary collapse
- HOST =
"localhost"
Instance Method Summary collapse
-
#assistant_role ⇒ String
Returns the role of the assistant in the conversation.
-
#complete(prompt, params = {}) ⇒ LLM::Response
Provides an interface to the chat completions API.
-
#default_model ⇒ String
Returns the default model for chat completions.
-
#embed(input, model: default_model, **params) ⇒ LLM::Response
Provides an embedding.
-
#initialize ⇒ Ollama
constructor
A new instance of Ollama.
-
#models ⇒ LLM::Ollama::Models
Provides an interface to Ollama's models API.
Methods inherited from Provider
#audio, #chat, clients, #developer_role, #files, #images, #inspect, #moderations, #respond, #responses, #schema, #server_tool, #server_tools, #system_role, #user_role, #vector_stores, #web_search, #with
Constructor Details
Instance Method Details
#assistant_role ⇒ String
Returns the role of the assistant in the conversation. Usually "assistant" or "model"
78 79 80 |
# File 'lib/llm/providers/ollama.rb', line 78 def assistant_role "assistant" end |
#complete(prompt, params = {}) ⇒ LLM::Response
Provides an interface to the chat completions API
60 61 62 63 64 65 66 |
# File 'lib/llm/providers/ollama.rb', line 60 def complete(prompt, params = {}) params, stream, tools, role = normalize_complete_params(params) req = build_complete_request(prompt, params, role) res = execute(request: req, stream: stream) ResponseAdapter.adapt(res, type: :completion) .extend(Module.new { define_method(:__tools__) { tools } }) end |
#default_model ⇒ String
Returns the default model for chat completions
86 87 88 |
# File 'lib/llm/providers/ollama.rb', line 86 def default_model "qwen3:latest" end |
#embed(input, model: default_model, **params) ⇒ LLM::Response
Provides an embedding
42 43 44 45 46 47 48 |
# File 'lib/llm/providers/ollama.rb', line 42 def (input, model: default_model, **params) params = {model:}.merge!(params) req = Net::HTTP::Post.new("/v1/embeddings", headers) req.body = LLM.json.dump({input:}.merge!(params)) res = execute(request: req) ResponseAdapter.adapt(res, type: :embedding) end |
#models ⇒ LLM::Ollama::Models
Provides an interface to Ollama's models API
72 73 74 |
# File 'lib/llm/providers/ollama.rb', line 72 def models LLM::Ollama::Models.new(self) end |