Skip to content

Commit 119cb7d

Browse files
committed
improve dialogue prompts
1 parent dab8b0d commit 119cb7d

File tree

2 files changed

+35
-34
lines changed

2 files changed

+35
-34
lines changed

app/controllers/conversation_controller.rb

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,21 @@ def character_landing
1616

1717
def export
1818
name = open_characters_persona_params.fetch('name', 'New character').strip
19-
personality = open_characters_persona_params.fetch('personality', '')
2019
description = open_characters_persona_params.fetch('description', '')
2120

2221
add_character_hash = base_open_characters_export.merge({
2322
"uuid": deterministic_uuid(@character.id),
2423
"name": name,
25-
"roleInstruction": "You are to act as #{name}, whose personality is detailed below:\n\n#{description}",
26-
"reminderMessage": "#{personality}\n\n[AI]: (Thought: I need to remember to be very descriptive, and create an engaging experience for the user)",
24+
"roleInstruction": full_role_instruction,
25+
"reminderMessage": reminder_message,
2726
})
2827

2928
# Add a character image if one has been uploaded to the page
3029
avatar = @character.random_image_including_private
3130
add_character_hash[:avatar][:url] = avatar if avatar.present?
3231

3332
# Provide a default scenario if one wasn't given
34-
add_character_hash[:scenario] ||= "You are talking"
33+
add_character_hash[:scenario] ||= default_scenario
3534

3635
# Redirect to OpenCharacters
3736
base_oc_url = 'https://josephrocca.github.io/OpenCharacters/'
@@ -49,26 +48,34 @@ def deterministic_uuid(id)
4948
uuid
5049
end
5150

51+
def full_role_instruction
52+
final_text = [
53+
"[SYSTEM]: You are roleplaying as #{@character.name}, #{personality_for_character}",
54+
"",
55+
"Follow this pattern:",
56+
"\"Hello!\" - dialogue",
57+
"*He jumps out of the bushes.* - action",
58+
"",
59+
"#{@character.name}'s personality is below:",
60+
"#{open_characters_persona_params.fetch('description', '(not included)')}",
61+
"",
62+
"#{@character.name} will now respond while staying in character in an extremely descriptive manner at length, avoiding being repetitive, without advancing events by herself, avoiding implying conversations without a reply from the user first, and wait for the user's reply to advance events. Describe what #{@character.name} is feeling, saying, and doing with rich detail, but do not include any parenthetical thoughts and focus primarily on dialogue.",
63+
].join("\n")
64+
end
65+
66+
def reminder_message
67+
"[SYSTEM]: (Thought: I need to rememeber to be creative, descriptive, and engaging! I should work very hard to avoid being repetitive as well! Unless the user speaks to me OOC, with parentheses around their input, first, I will not say anything OOC or in parentheses. I shouldn't ignore parts of the user's post, even if they move on to a new scene. I should at least write my characters thoughts and feelings towards the prior scene before continuing with the new one. I don't need to feel the need to write a long response if the user's post is short. In that case, I can feel free to write a short response myself - making sure to not take over writing the user's character's dialogue, thoughts, or actions!)"
68+
end
69+
5270
def personality_for_character
53-
name = @character.name
54-
gender = @character.get_field_value('Overview', 'Gender').try(:strip)
55-
role = @character.get_field_value('Overview', 'Role').try(:strip)
56-
age = @character.get_field_value('Overview', 'Age').try(:strip)
57-
aliases = @character.get_field_value('Overview', 'Aliases').try(:strip)
58-
hobbies = @character.get_field_value('Nature', 'Hobbies').try(:strip)
71+
hobbies = @character.get_field_value('Nature', 'Hobbies')
5972

60-
final_text = [
61-
name,
62-
" is a ",
63-
gender.downcase,
64-
" ",
65-
role || "character",
66-
age.present? ? ", #{age}," : nil,
67-
aliases.present? ? "(also known as #{aliases})" : nil,
68-
hobbies.present? ? " into #{hobbies}." : "."
69-
].compact.join
73+
personality_parts = [
74+
"a #{@character.get_field_value('Overview', 'Gender', fallback='')} #{@character.get_field_value('Overview', 'Role', fallback='character')}, age #{@character.get_field_value('Overview', 'Age', fallback='irrelevant')}."
75+
]
76+
personality_parts << "Their hobbies include #{hobbies}." if hobbies.present?
7077

71-
ContentFormatterService.plaintext_show(text: final_text, viewing_user: current_user)
78+
ContentFormatterService.plaintext_show(text: personality_parts.join(' '), viewing_user: current_user)
7279
end
7380

7481
def description_for_character
@@ -110,11 +117,7 @@ def open_characters_persona_params
110117
end
111118

112119
def default_scenario
113-
""
114-
end
115-
116-
def default_reminder_message
117-
""
120+
"This character is interacting with the user within their own fictional universe. The character will respond in a way that is consistent with their personality and background."
118121
end
119122

120123
def default_custom_code
@@ -126,8 +129,6 @@ def default_custom_code
126129
def base_open_characters_export
127130
{
128131
"name": "New character",
129-
# "roleInstruction": default_scenario,
130-
# "reminderMessage": default_reminder_message,
131132
"modelName": "gpt-3.5-turbo",
132133
"fitMessagesInContextMethod": "summarizeOld",
133134
"associativeMemoryMethod": "v1",
@@ -163,7 +164,7 @@ def default_initial_messages
163164
[
164165
{
165166
"author": "system",
166-
"content": open_characters_persona_params.fetch('scenario', default_scenario),
167+
"content": "Scenario: " + (open_characters_persona_params.fetch('scenario', nil).presence || default_scenario),
167168
"hiddenFrom": [] # "ai", "user", "both", "neither"
168169
},
169170
{
@@ -190,6 +191,6 @@ def default_export_metadata
190191
end
191192

192193
def default_character_greeting
193-
"Hello, friend!"
194+
"Hello!"
194195
end
195196
end

app/models/concerns/has_attributes.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -300,30 +300,30 @@ def overview_field_value(label)
300300
.detect { |v| v.entity_id == self.id }&.value.presence || (self.respond_to?(label.downcase) ? self.read_attribute(label.downcase) : nil)
301301
end
302302

303-
def get_field_value(category, field)
303+
def get_field_value(category, field, fallback=nil)
304304
category = AttributeCategory.find_by(
305305
label: category,
306306
entity_type: self.class.name.downcase,
307307
user_id: self.user_id,
308308
hidden: [nil, false]
309309
)
310-
return nil if category.nil?
310+
return fallback if category.nil?
311311

312312
field = AttributeField.find_by(
313313
label: field,
314314
attribute_category_id: category.id,
315315
user_id: self.user_id,
316316
hidden: [nil, false]
317317
)
318-
return nil if field.nil?
318+
return fallback if field.nil?
319319

320320
answer = Attribute.find_by(
321321
attribute_field_id: field.id,
322322
entity_type: self.class.name,
323323
entity_id: self.id,
324324
user_id: self.user_id
325325
)
326-
return nil if answer.nil?
326+
return fallback if answer.nil?
327327

328328
answer.value
329329
end

0 commit comments

Comments
 (0)