Class: AwesomeChatgptActors::Actor

Inherits:
Object
  • Object
show all
Defined in:
lib/awesome_chatgpt_actors/actor.rb

Overview

This class is the implementation of Awesome Chatgpt Prompts with improvements

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(role: "Virtual Assistant", prompt: nil, language: "en", random: false, has_placeholder: false, accertivity: 1, default_frequency: 0, default_presence: 0) ⇒ Actor

Returns a new instance of Actor.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/awesome_chatgpt_actors/actor.rb', line 6

def initialize(role: "Virtual Assistant", prompt: nil,  language: "en",  random: false,
                has_placeholder: false, accertivity: 1, default_frequency: 0, default_presence: 0)          
  @csv_path = CastControl.csv_path if language == "en"
  @csv_path = CastControl.csv_path.gsub("en", language) if language != "en"
  @language = language || "en"
  @actors_csv = CSV.read(@csv_path, headers: true)
  @role = role
  @prompt = prompt
  @random = random
  @accertivity = accertivity
  @default_frequency = default_frequency
  @default_presence = default_presence
  @has_placeholder = has_placeholder
  act_as(role) unless random || prompt
  act_as(random_actor) if random
end

Instance Attribute Details

#accertivityObject

Returns the value of attribute accertivity.



23
24
25
# File 'lib/awesome_chatgpt_actors/actor.rb', line 23

def accertivity
  @accertivity
end

#actors_csvObject

Returns the value of attribute actors_csv.



23
24
25
# File 'lib/awesome_chatgpt_actors/actor.rb', line 23

def actors_csv
  @actors_csv
end

#csv_pathObject (readonly)

Returns the value of attribute csv_path.



24
25
26
# File 'lib/awesome_chatgpt_actors/actor.rb', line 24

def csv_path
  @csv_path
end

#default_frequencyObject

Returns the value of attribute default_frequency.



23
24
25
# File 'lib/awesome_chatgpt_actors/actor.rb', line 23

def default_frequency
  @default_frequency
end

#default_presenceObject

Returns the value of attribute default_presence.



23
24
25
# File 'lib/awesome_chatgpt_actors/actor.rb', line 23

def default_presence
  @default_presence
end

#has_placeholderObject

Returns the value of attribute has_placeholder.



23
24
25
# File 'lib/awesome_chatgpt_actors/actor.rb', line 23

def has_placeholder
  @has_placeholder
end

#promptObject

Returns the value of attribute prompt.



23
24
25
# File 'lib/awesome_chatgpt_actors/actor.rb', line 23

def prompt
  @prompt
end

#randomObject (readonly)

Returns the value of attribute random.



24
25
26
# File 'lib/awesome_chatgpt_actors/actor.rb', line 24

def random
  @random
end

#roleObject

Returns the value of attribute role.



23
24
25
# File 'lib/awesome_chatgpt_actors/actor.rb', line 23

def role
  @role
end

Instance Method Details

#act_as(role = "Virtual Assistant") ⇒ Object

Raises:

  • (ArgumentError)


26
27
28
29
30
31
32
33
34
35
36
# File 'lib/awesome_chatgpt_actors/actor.rb', line 26

def act_as(role = "Virtual Assistant")
  @role = role
  actor_row = actors_csv.select { |row| row["act"] == role }
  raise ArgumentError, "Role not found: #{role}" if actor_row.empty?
  @prompt = actor_row.sample["prompt"]
  @accertivity = actor_row.sample["accertivity"].to_i
  @default_frequency = actor_row.sample["default_frequency"].to_i
  @default_presence = actor_row.sample["default_presence"].to_i
  @has_placeholder = actor_row.sample["has_placeholder"] == "false" ? false : true
  self
end