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
-
#initialize ⇒
Ollama constructor
A new instance of Ollama.
-
#embed(input,
model: default_model, **params) ⇒ LLM::Response
Provides an embedding.
-
#complete(prompt,
params = {}) ⇒ LLM::Response
Provides an interface to the chat completions API.
-
#models ⇒
LLM::Ollama::Models
Provides an interface to Ollama's models API.
-
#assistant_role
⇒ String
Returns the role of the assistant in the conversation.
-
#default_model ⇒
String
Returns the default model for chat completions.
Methods inherited from Provider
#audio, #chat, clients, #developer_role, #files, #images, #inspect, #moderations, #respond, #responses, #schema, #server_tool, #server_tools, #system_role, #tracer, #tracer=, #user_role, #vector_stores, #web_search, #with
Constructor Details
Instance Method Details
#embed(input, model: default_model, **params) ⇒ LLM::Response
Provides an embedding
42 43 44 45 46 47 48 49 |
# 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, span = execute(request: req, operation: "embeddings", model:) res = ResponseAdapter.adapt(res, type: :embedding) finish_trace(operation: "embeddings", model:, res:, span:) end |
#complete(prompt, params = {}) ⇒ LLM::Response
Provides an interface to the chat completions API
61 62 63 64 65 66 67 68 |
# File 'lib/llm/providers/ollama.rb', line 61 def complete(prompt, params = {}) params, stream, tools, role = normalize_complete_params(params) req = build_complete_request(prompt, params, role) res, span = execute(request: req, stream: stream, operation: "chat", model: params[:model]) res = ResponseAdapter.adapt(res, type: :completion) .extend(Module.new { define_method(:__tools__) { tools } }) finish_trace(operation: "chat", model: params[:model], res:, span:) end |
#models ⇒ LLM::Ollama::Models
Provides an interface to Ollama's models API
74 75 76 |
# File 'lib/llm/providers/ollama.rb', line 74 def models LLM::Ollama::Models.new(self) end |
#assistant_role ⇒ String
Returns the role of the assistant in the conversation. Usually "assistant" or "model"
80 81 82 |
# File 'lib/llm/providers/ollama.rb', line 80 def assistant_role "assistant" end |
#default_model ⇒ String
Returns the default model for chat completions
88 89 90 |
# File 'lib/llm/providers/ollama.rb', line 88 def default_model "qwen3:latest" end |