Class: Ollama::Commands::Create
- Inherits:
- 
      Object
      
        - Object
- Ollama::Commands::Create
 
- Includes:
- DTO
- Defined in:
- lib/ollama/commands/create.rb
Overview
A command class that represents the create API endpoint for Ollama.
This class is used to interact with the Ollama API’s create endpoint, which creates a new model based on a modelfile or existing model. It inherits from the base command structure and provides the necessary functionality to execute model creation requests.
Instance Attribute Summary collapse
- 
  
    
      #adapters  ⇒ Hash? 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    The adapters attribute reader returns the adapter files associated with the object. 
- 
  
    
      #client  ⇒ Object 
    
    
  
  
  
  
    
    
      writeonly
    
  
  
  
  
  
  
    The client attribute writer allows setting the client instance associated with the object. 
- 
  
    
      #files  ⇒ Hash? 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    The files attribute reader returns the file contents associated with the object. 
- 
  
    
      #from  ⇒ String? 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    The from attribute reader returns the base model name associated with the object. 
- 
  
    
      #license  ⇒ String, ... 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    The license attribute reader returns the license(s) associated with the object. 
- 
  
    
      #messages  ⇒ Array<Ollama::Message>? 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    The messages attribute reader returns the initial conversation messages associated with the object. 
- 
  
    
      #model  ⇒ String 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    The model attribute reader returns the model name associated with the object. 
- 
  
    
      #parameters  ⇒ Ollama::Options? 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    The parameters attribute reader returns the model configuration parameters associated with the object. 
- 
  
    
      #quantize  ⇒ String? 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    The quantize attribute reader returns the quantization method associated with the object. 
- 
  
    
      #stream  ⇒ TrueClass, FalseClass 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    The stream attribute reader returns the streaming behavior setting associated with the object. 
- 
  
    
      #system  ⇒ String? 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    The system attribute reader returns the system prompt associated with the object. 
Class Method Summary collapse
- 
  
    
      .path  ⇒ String 
    
    
  
  
  
  
  
  
  
  
  
    The path method returns the API endpoint path for create requests. 
Instance Method Summary collapse
- 
  
    
      #initialize(model:, from: nil, files: nil, adapters: nil, template: nil, license: nil, system: nil, parameters: nil, messages: nil, stream: true, quantize: nil)  ⇒ Create 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    The initialize method sets up a new instance with streaming enabled by default. 
- 
  
    
      #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:, from: nil, files: nil, adapters: nil, template: nil, license: nil, system: nil, parameters: nil, messages: nil, stream: true, quantize: nil) ⇒ Create
The initialize method sets up a new instance with streaming enabled by default.
This method is responsible for initializing a new object instance and configuring it with parameters required for model creation. It sets up the model name, source model (if any), files, adapters, template, license, system prompt, parameters, messages, and streaming behavior.
| 50 51 52 53 54 | # File 'lib/ollama/commands/create.rb', line 50 def initialize(model:, from: nil, files: nil, adapters: nil, template: nil, license: nil, system: nil, parameters: nil, messages: nil, stream: true, quantize: nil) @model, @from, @files, @adapters, @license, @system, @parameters, @messages, @stream, @quantize = model, from, as_hash(files), as_hash(adapters), as_array(license), system, as_hash(parameters), as_array_of_hashes(), stream, quantize end | 
Instance Attribute Details
#adapters ⇒ Hash? (readonly)
The adapters attribute reader returns the adapter files associated with the object.
| 74 75 76 | # File 'lib/ollama/commands/create.rb', line 74 def adapters @adapters end | 
#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.
| 116 117 118 | # File 'lib/ollama/commands/create.rb', line 116 def client=(value) @client = value end | 
#files ⇒ Hash? (readonly)
The files attribute reader returns the file contents associated with the object.
| 69 70 71 | # File 'lib/ollama/commands/create.rb', line 69 def files @files end | 
#from ⇒ String? (readonly)
The from attribute reader returns the base model name associated with the object.
| 64 65 66 | # File 'lib/ollama/commands/create.rb', line 64 def from @from end | 
#license ⇒ String, ... (readonly)
The license attribute reader returns the license(s) associated with the object.
| 79 80 81 | # File 'lib/ollama/commands/create.rb', line 79 def license @license end | 
#messages ⇒ Array<Ollama::Message>? (readonly)
The messages attribute reader returns the initial conversation messages associated with the object.
| 94 95 96 | # File 'lib/ollama/commands/create.rb', line 94 def @messages end | 
#model ⇒ String (readonly)
The model attribute reader returns the model name associated with the object.
| 59 60 61 | # File 'lib/ollama/commands/create.rb', line 59 def model @model end | 
#parameters ⇒ Ollama::Options? (readonly)
The parameters attribute reader returns the model configuration parameters associated with the object.
| 89 90 91 | # File 'lib/ollama/commands/create.rb', line 89 def parameters @parameters end | 
#quantize ⇒ String? (readonly)
The quantize attribute reader returns the quantization method associated with the object.
| 106 107 108 | # File 'lib/ollama/commands/create.rb', line 106 def quantize @quantize end | 
#stream ⇒ TrueClass, FalseClass (readonly)
The stream attribute reader returns the streaming behavior setting associated with the object.
| 101 102 103 | # File 'lib/ollama/commands/create.rb', line 101 def stream @stream end | 
#system ⇒ String? (readonly)
The system attribute reader returns the system prompt associated with the object.
| 84 85 86 | # File 'lib/ollama/commands/create.rb', line 84 def system @system end | 
Class Method Details
.path ⇒ String
The path method returns the API endpoint path for create requests.
This class method provides the specific URL path used to interact with the Ollama API’s create endpoint. It is utilized internally by the command structure to determine the correct API route for creating new models.
| 28 29 30 | # File 'lib/ollama/commands/create.rb', line 28 def self.path '/api/create' 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 create endpoint, utilizing the client instance to send the request and process responses through the provided handler. It handles both streaming and non-streaming scenarios based on the command’s configuration.
responses
| 129 130 131 | # File 'lib/ollama/commands/create.rb', line 129 def perform(handler) @client.request(method: :post, path: self.class.path, body: to_json, stream:, handler:) end |