Class: Ollama::Commands::Embed
- Inherits:
-
Object
- Object
- Ollama::Commands::Embed
- Includes:
- DTO
- Defined in:
- lib/ollama/commands/embed.rb
Overview
A command class that represents the embed API endpoint for Ollama.
This class is used to interact with the Ollama API's embed endpoint, which generates embeddings for text input using a specified model. It inherits from the base command structure and provides the necessary functionality to execute embedding requests for generating vector representations of text.
Instance Attribute Summary collapse
-
#client ⇒ Object
writeonly
The client attribute writer allows setting the client instance associated with the object.
-
#input ⇒ String+
readonly
The input attribute reader returns the text input(s) associated with the object.
-
#keep_alive ⇒ String?
readonly
The keep_alive attribute reader returns the keep-alive duration associated with the object.
-
#model ⇒ String
readonly
The model attribute reader returns the model name associated with the object.
-
#options ⇒ Ollama::Options?
readonly
The options attribute reader returns the model configuration options associated with the object.
-
#stream ⇒ FalseClass
readonly
The stream attribute reader returns the streaming behavior setting associated with the object.
-
#truncate ⇒ Boolean?
readonly
The truncate attribute reader returns the truncate setting associated with the object.
Class Method Summary collapse
-
.path ⇒ String
The path method returns the API endpoint path for embed requests.
Instance Method Summary collapse
-
#initialize(model:, input:, options: nil, truncate: nil, keep_alive: nil) ⇒ Embed
constructor
The initialize method sets up a new instance with streaming disabled.
-
#perform(handler) ⇒ self
The perform method executes a command request using the specified handler.
Methods included from DTO
#==, #as_array, #as_array_of_hashes, #as_hash, #as_json, #empty?, #to_json
Constructor Details
#initialize(model:, input:, options: nil, truncate: nil, keep_alive: nil) ⇒ Embed
The initialize method sets up a new instance with streaming disabled.
This method is responsible for initializing a new object instance and configuring it with parameters required for embedding operations. It sets up the model, input text(s), and optional parameters while explicitly disabling streaming since embedding operations are typically non-streaming.
39 40 41 42 43 |
# File 'lib/ollama/commands/embed.rb', line 39 def initialize(model:, input:, options: nil, truncate: nil, keep_alive: nil) @model, @input, @options, @truncate, @keep_alive = model, input, , truncate, keep_alive @stream = false end |
Instance Attribute Details
#client=(value) ⇒ Object (writeonly)
The client attribute writer allows setting the client instance associated with the object.
This method assigns the client that will be used to perform requests and handle responses for this command. It is typically called internally when a command is executed through a client instance.
86 87 88 |
# File 'lib/ollama/commands/embed.rb', line 86 def client=(value) @client = value end |
#input ⇒ String+ (readonly)
The input attribute reader returns the text input(s) associated with the object.
53 54 55 |
# File 'lib/ollama/commands/embed.rb', line 53 def input @input end |
#keep_alive ⇒ String? (readonly)
The keep_alive attribute reader returns the keep-alive duration associated with the object.
68 69 70 |
# File 'lib/ollama/commands/embed.rb', line 68 def keep_alive @keep_alive end |
#model ⇒ String (readonly)
The model attribute reader returns the model name associated with the object.
48 49 50 |
# File 'lib/ollama/commands/embed.rb', line 48 def model @model end |
#options ⇒ Ollama::Options? (readonly)
The options attribute reader returns the model configuration options associated with the object.
58 59 60 |
# File 'lib/ollama/commands/embed.rb', line 58 def @options end |
#stream ⇒ FalseClass (readonly)
The stream attribute reader returns the streaming behavior setting associated with the object.
75 76 77 |
# File 'lib/ollama/commands/embed.rb', line 75 def stream @stream end |
#truncate ⇒ Boolean? (readonly)
The truncate attribute reader returns the truncate setting associated with the object.
63 64 65 |
# File 'lib/ollama/commands/embed.rb', line 63 def truncate @truncate end |
Class Method Details
.path ⇒ String
The path method returns the API endpoint path for embed requests.
This class method provides the specific URL path used to interact with the Ollama API's embed endpoint. It is utilized internally by the command structure to determine the correct API route for generating embeddings.
23 24 25 |
# File 'lib/ollama/commands/embed.rb', line 23 def self.path '/api/embed' end |
Instance Method Details
#perform(handler) ⇒ self
The perform method executes a command request using the specified handler.
This method initiates a POST request to the Ollama API's embed endpoint, utilizing the client instance to send the request and process responses through the provided handler. It handles non-streaming scenarios since embedding commands do not support streaming.
responses
99 100 101 |
# File 'lib/ollama/commands/embed.rb', line 99 def perform(handler) @client.request(method: :post, path: self.class.path, body: to_json, stream:, handler:) end |