Class: Richat::Cli

Inherits:
Object
  • Object
show all
Defined in:
lib/richat/cli.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Cli

Returns a new instance of Cli.



5
6
7
8
9
# File 'lib/richat/cli.rb', line 5

def initialize(options = {})
  @chat_client = options[:chat_client]
  @logger = options[:logger]
  @user_content = options[:user_content]
end

Instance Attribute Details

#chat_clientObject (readonly)

Returns the value of attribute chat_client.



3
4
5
# File 'lib/richat/cli.rb', line 3

def chat_client
  @chat_client
end

#loggerObject (readonly)

Returns the value of attribute logger.



3
4
5
# File 'lib/richat/cli.rb', line 3

def logger
  @logger
end

#user_contentObject (readonly)

Returns the value of attribute user_content.



3
4
5
# File 'lib/richat/cli.rb', line 3

def user_content
  @user_content
end

Instance Method Details

#callObject



11
12
13
14
15
16
17
18
19
# File 'lib/richat/cli.rb', line 11

def call
  logger.call(role: Config.get("log", "user_role"), content: user_content)
  response = chat_client.call([{ role: 'user', content: user_content }])

  if !response.nil? && !response.empty?
    logger.call(role: Config.get("log", "ai_role"), content: response)
    puts response
  end
end