Module: Ollama::Client::Command::ClassMethods

Defined in:
lib/ollama/client/command.rb

Instance Method Summary collapse

Instance Method Details

#command(name, default_handler:, stream_handler: nil) ⇒ Object

Create Command name, if stream was true, set stream_handler as default, otherwise default_handler.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/ollama/client/command.rb', line 7

def command(name, default_handler:, stream_handler: nil)
  klass = Ollama::Commands.const_get(name.to_s.camelize)
  doc Ollama::Client::Doc.new(name)
  define_method(name) do |**parameters, &handler|
    instance = klass.new(**parameters)
    instance.client = self
    unless handler
      instance.stream and stream_handler and
        handler ||= stream_handler
      handler ||= default_handler
    end
    handler.is_a?(Class) and handler = handler.new
    instance.perform(handler)
    handler.result if handler.respond_to?(:result)
  end
  self
end