module Ollama::Client::Command

def command(name, default_handler:, stream_handler: nil)

Returns:
  • (self) - returns the receiver after defining the command method

Other tags:
    Note: - Create Command `name`, if `stream` was true, set `stream_handler`

Parameters:
  • stream_handler (Class, nil) -- the handler class to use for streaming responses, if applicable
  • default_handler (Class) -- the default handler class to use when no explicit handler is provided
  • name (Symbol) -- the name of the command to define
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