Class: OmniAI::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/omniai/cli.rb,
lib/omniai/cli/base_handler.rb,
lib/omniai/cli/chat_handler.rb,
lib/omniai/cli/embed_handler.rb

Overview

Used when interacting with the suite from the command line interface (CLI).

Usage:

cli = OmniAI::CLI.new
cli.parse

Defined Under Namespace

Classes: BaseHandler, ChatArgs, ChatHandler, EmbedHandler

Instance Method Summary collapse

Constructor Details

#initialize(stdin: $stdin, stdout: $stdout, provider: 'openai') ⇒ CLI

Returns a new instance of CLI.

Parameters:

  • stdin (IO) (defaults to: $stdin)

    a stream

  • stdout (IO) (defaults to: $stdout)

    a stream

  • provider (String) (defaults to: 'openai')

    a provider



18
19
20
21
22
23
# File 'lib/omniai/cli.rb', line 18

def initialize(stdin: $stdin, stdout: $stdout, provider: 'openai')
  @stdin = stdin
  @stdout = stdout
  @provider = provider
  @args = {}
end

Instance Method Details

#parse(argv = ARGV) ⇒ Object

Parameters:

  • argv (Array<String>) (defaults to: ARGV)


26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/omniai/cli.rb', line 26

def parse(argv = ARGV)
  parser.order!(argv)
  command = argv.shift
  return if command.nil?

  handler =
    case command
    when 'chat' then ChatHandler
    when 'embed' then EmbedHandler
    else raise Error, "unsupported command=#{command.inspect}"
    end

  handler.handle!(stdin: @stdin, stdout: @stdout, provider: @provider, argv:)
end