@@ -3,14 +3,28 @@ class ConversationController < ApplicationController
33 before_action :ensure_character_privacy
44
55 def character_landing
6- @first_greeting = "Hello, friend!"
7-
8- @personality = personality_for_character
9- @description = description_for_character
6+ @first_greeting = default_character_greeting
7+ @personality = personality_for_character
8+ @description = description_for_character
109 end
1110
1211 def export
13- raise open_characters_persona_params . inspect
12+ add_character_hash = base_open_characters_export . merge ( {
13+ "name" : open_characters_persona_params . fetch ( 'name' , 'New character' ) ,
14+ "roleInstruction" : "You are to act as #{ @character . name } , whos personality is detailed below:\n \n #{ description_for_character } " ,
15+ "reminderMessage" : "#{ personality_for_character } Do not break character!" ,
16+ } )
17+
18+ # Add a character image if one has been uploaded to the page
19+ avatar = @character . random_image_including_private
20+ add_character_hash [ :avatar ] [ :url ] = avatar if avatar . present?
21+
22+ # Redirect to OpenCharacters
23+
24+ base_oc_url = 'https://josephrocca.github.io/OpenCharacters/'
25+ oc_params = { addCharacter : add_character_hash }
26+
27+ redirect_to "#{ base_oc_url } ##{ ERB ::Util . url_encode ( oc_params ) } "
1428 end
1529
1630 private
@@ -65,10 +79,95 @@ def set_character
6579 def ensure_character_privacy
6680 unless ( user_signed_in? && @character . user == current_user ) || @character . privacy == 'public'
6781 redirect_to root_path , notice : "That character is private!"
82+ return
6883 end
6984 end
7085
7186 def open_characters_persona_params
7287 params . permit ( :name , :avatar , :scenario , :char_greeting , :personality , :description , :example_dialogue )
7388 end
89+
90+ def default_scenario
91+ ""
92+ end
93+
94+ def default_reminder_message
95+ ""
96+ end
97+
98+ def default_custom_code
99+ ""
100+
101+ # TODO maybe include our standard (whisper) formatting on messages?
102+ end
103+
104+ def base_open_characters_export
105+ {
106+ "name" : "New character" ,
107+ # "roleInstruction": default_scenario,
108+ # "reminderMessage": default_reminder_message,
109+ "modelName" : "gpt-3.5-turbo" ,
110+ "fitMessagesInContextMethod" : "summarizeOld" ,
111+ "associativeMemoryMethod" : "v1" ,
112+ "associativeMemoryEmbeddingModelName" : "text-embedding-ada-002" ,
113+ "temperature" : 0.7 ,
114+ "customCode" : default_custom_code ,
115+ "initialMessages" : default_initial_messages ,
116+ "avatar" : {
117+ "url" : "" ,
118+ "size" : 1 ,
119+ "shape" : "square"
120+ } ,
121+ "scene" : {
122+ "background" : {
123+ "url" : ""
124+ } ,
125+ "music" : {
126+ "url" : ""
127+ }
128+ } ,
129+ "userCharacter" : {
130+ "avatar" : {
131+ "url" : current_user . avatar . url ,
132+ "size" : 1 ,
133+ "shape" : "circle"
134+ }
135+ } ,
136+ "streamingResponse" : true
137+ }
138+ end
139+
140+ def default_initial_messages
141+ [
142+ {
143+ "author" : "system" ,
144+ "content" : open_characters_persona_params . fetch ( 'scenario' , default_scenario ) ,
145+ "hiddenFrom" : [ ] # "ai", "user", "both", "neither"
146+ } ,
147+ {
148+ "author" : "ai" ,
149+ "content" : open_characters_persona_params . fetch ( 'char_greeting' , default_character_greeting ) ,
150+ "hiddenFrom" : [ ]
151+ }
152+ ]
153+ end
154+
155+ def default_export_metadata
156+ {
157+ "version" : 1 ,
158+ "created" : @content . created_at . to_i ,
159+ "modified" : @content . updated_at . to_i ,
160+ "ncid" : @content . id ,
161+ "source" : "https://www.notebook.ai/plan/characters#{ @content . id } " ,
162+ "tool" : {
163+ "name" : "Notebook.ai Persona Export" ,
164+ "version" : "1.0.0" ,
165+ "url" : "https://www.notebook.ai"
166+ }
167+ }
168+ end
169+
170+ def default_character_greeting
171+ "Hello, friend!"
172+ end
74173end
0 commit comments