Class: Ruboty::OpenAIChat::Actions::Base Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/ruboty/openai_chat/actions/base.rb

Overview

This class is abstract.

Direct Known Subclasses

Chat, RememberProfile, ShowProfile

Constant Summary collapse

NAMESPACE =
"openai-chat-actions-chat"
PROFILE_KEY =
"profile"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message) ⇒ Base

Returns a new instance of Base.

Parameters:

  • message (Ruboty::Message)


14
15
16
# File 'lib/ruboty/openai_chat/actions/base.rb', line 14

def initialize(message)
  @message = message
end

Instance Attribute Details

#messageObject (readonly)

Returns the value of attribute message.



11
12
13
# File 'lib/ruboty/openai_chat/actions/base.rb', line 11

def message
  @message
end

Instance Method Details

#clientOpenAI::Client

Returns:

  • (OpenAI::Client)


19
20
21
22
# File 'lib/ruboty/openai_chat/actions/base.rb', line 19

def client
  @client ||= OpenAI::Client.new(access_token: ENV.fetch("OPENAI_ACCESS_TOKEN"),
                                 organization_id: ENV.fetch("OPENAI_ORGANIZATION_ID"))
end

#memoryMemory

Returns:



30
31
32
# File 'lib/ruboty/openai_chat/actions/base.rb', line 30

def memory
  @memory ||= Memory.new(robot)
end

#openai_modelString

Returns:

  • (String)


40
41
42
# File 'lib/ruboty/openai_chat/actions/base.rb', line 40

def openai_model
  ENV["OPENAI_CHAT_MODEL"] || "gpt-3.5-turbo"
end

#pretextsArray<String>

Returns:

  • (Array<String>)


35
36
37
# File 'lib/ruboty/openai_chat/actions/base.rb', line 35

def pretexts
  [ENV["OPENAI_CHAT_PRETEXT"], memory.namespace(NAMESPACE)[PROFILE_KEY]].compact
end

#robotRuboty::Robot

Returns:

  • (Ruboty::Robot)


25
26
27
# File 'lib/ruboty/openai_chat/actions/base.rb', line 25

def robot
  message.robot
end