Skip to content

Commit dab8b0d

Browse files
committed
conversations index page to use instead of chat links on individual pages
1 parent 76f4aed commit dab8b0d

File tree

6 files changed

+130
-57
lines changed

6 files changed

+130
-57
lines changed

app/controllers/conversation_controller.rb

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
class ConversationController < ApplicationController
2-
before_action :set_character
3-
before_action :ensure_character_privacy
2+
before_action :authenticate_user!, only: [:character_index]
3+
4+
before_action :set_character, only: [:character_landing, :export]
5+
before_action :ensure_character_privacy, only: [:character_landing, :export]
6+
7+
def character_index
8+
@characters = @current_user_content.fetch('Character', [])
9+
end
410

511
def character_landing
612
@first_greeting = default_character_greeting
@@ -17,13 +23,16 @@ def export
1723
"uuid": deterministic_uuid(@character.id),
1824
"name": name,
1925
"roleInstruction": "You are to act as #{name}, whose personality is detailed below:\n\n#{description}",
20-
"reminderMessage": "#{personality}\n\nDo not break character!",
26+
"reminderMessage": "#{personality}\n\n[AI]: (Thought: I need to remember to be very descriptive, and create an engaging experience for the user)",
2127
})
2228

2329
# Add a character image if one has been uploaded to the page
2430
avatar = @character.random_image_including_private
2531
add_character_hash[:avatar][:url] = avatar if avatar.present?
2632

33+
# Provide a default scenario if one wasn't given
34+
add_character_hash[:scenario] ||= "You are talking"
35+
2736
# Redirect to OpenCharacters
2837
base_oc_url = 'https://josephrocca.github.io/OpenCharacters/'
2938
oc_params = { addCharacter: add_character_hash }

app/models/concerns/has_image_uploads.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def random_image_including_private(format: :medium)
2626

2727
# If we don't have any uploaded images, we look for saved Basil commissions
2828
if result.nil? && respond_to?(:basil_commissions)
29-
result = basil_commissions.where.not(saved_at: nil).sample.try(:image)
29+
result = basil_commissions.where.not(saved_at: nil).includes([:image_attachment]).sample.try(:image)
3030
end
3131

3232
# Finally, if we have no image upload, we return the default image for this type

app/models/page_types/content_page.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class ContentPage < ApplicationRecord
1111

1212
def random_image_including_private(format: :small)
1313
ImageUpload.where(content_type: self.page_type, content_id: self.id).sample.try(:src, format) \
14-
|| BasilCommission.where(entity_type: self.page_type, entity_id: self.id).where.not(saved_at: nil).sample.try(:image) \
14+
|| BasilCommission.where(entity_type: self.page_type, entity_id: self.id).where.not(saved_at: nil).includes([:image_attachment]).sample.try(:image) \
1515
|| ActionController::Base.helpers.asset_path("card-headers/#{self.page_type.downcase.pluralize}.webp")
1616
end
1717

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<div class="row">
2+
<div class="col s12">
3+
<h1 style="font-size: 2rem">
4+
<i class="material-icons float-right ">forum</i>
5+
Talk to your characters
6+
</h1>
7+
<p>
8+
There are a lot of new sites popping up for talking to AI characters. This page lets you
9+
export your Notebook.ai characters to those sites, starting with the open-source project
10+
OpenCharacters.
11+
</p>
12+
<p>
13+
Please note that these services aren't a part of Notebook.ai; this is just a way to get your
14+
Notebook.ai characters into those sites! To get started, click on any character below.
15+
</p>
16+
</div>
17+
</div>
18+
19+
<div class="row">
20+
<div class="col s12">
21+
<% if @universe_scope %>
22+
<div class="card-panel <%= Universe.color %> white-text">
23+
<i class="material-icons left"><%= Universe.icon %></i>
24+
Showing <%= pluralize @characters.count, 'character' %> from <%= @universe_scope.name %>.
25+
<%= link_to "Show characters from all universes instead.", conversation_path(universe: "all"), class: 'purple-text text-lighten-4' %>
26+
</div>
27+
<% end %>
28+
29+
<div class="row">
30+
<% @characters.each do |content| %>
31+
<%= link_to talk_path(content) do %>
32+
<div class="col s12 m4 l3">
33+
<div class="hoverable card">
34+
<div class="card-image">
35+
<%= image_tag content.random_image_including_private(format: :medium), style: 'height: 200px' %>
36+
<span class="card-title"><%= content.name %></span>
37+
</div>
38+
</div>
39+
</div>
40+
<% end %>
41+
<% end %>
42+
43+
<% if @characters.empty? %>
44+
<div class="center">
45+
<strong>You haven't created any character pages yet.</strong>
46+
<br /><br />
47+
48+
<%= link_to new_character_path, class: '' do %>
49+
<div class="hoverable card-panel <%= Character.color %> white-text" style="width: 33%; margin: 0 auto">
50+
<i class="material-icons left">add</i>
51+
Create character
52+
</div>
53+
<% end %>
54+
<div>
55+
<% end %>
56+
</div>
57+
</div>
58+
</div>
59+
60+

app/views/conversation/character_landing.html.erb

Lines changed: 54 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,89 @@
11
<div class="row">
2-
<div class="col s12 m3">
3-
<%= image_tag @character.random_image_including_private %>
2+
<div class="col s12 m4">
3+
<%= image_tag @character.random_image_including_private, style: "width: 100%" %>
44

5-
<div>
6-
<%= link_to "Back to #{@character.name}", @character %>
5+
<div class="card">
6+
<div class="card-content">
7+
<div class="card-title">
8+
<strong>Talk to <%= @character.name %></strong>
9+
</div>
10+
<p>
11+
You can now export your Notebook.ai characters to the open-source project OpenCharacters
12+
and talk to them in real-time! This is a great way to get to know your characters a little
13+
better or to roleplay with them.
14+
</p>
15+
</div>
716
</div>
8-
</div>
9-
<div class="col s12 m9">
10-
<h1 style="font-size: 1.4em">
11-
<strong>Talk to <%= @character.name %></strong>
12-
</h1>
13-
<p>
14-
You can now export your Notebook.ai characters to the open-source project OpenCharacters
15-
and talk to them in real-time! This is a great way to get to know your characters a little
16-
better or to roleplay with them.
17-
</p>
18-
<p>
19-
The fields below will be shared with OpenCharacters to create a conversational persona of
17+
18+
<p style="font-size: 0.9em">
19+
The fields will be used to create a conversational AI persona of
2020
your character. You can edit these fields before exporting if you want to change how your
2121
character talks. If your character is public, you can also share this page with others
2222
to let them talk to your character!
2323
</p>
24-
<br />
25-
24+
<div>
25+
<%= link_to "Back to notebook page", @character %>
26+
</div>
27+
</div>
28+
<div class="col s12 m8">
2629
<%= form_tag export_character_path(@character.id), method: :post do |f| %>
2730

2831
<%= hidden_field_tag "name", @character.name %>
2932
<%= hidden_field_tag "avatar", @character.random_image_including_private %>
3033
<%# TODO background image/music/etc? %>
3134

3235
<div class="card-panel">
33-
<p class="center">
34-
<strong>Persona export for <%= @character.name %></strong>
35-
<% if user_signed_in? && @character.user_id == current_user.id %>
36-
<br />
37-
<em>(editable because you created <%= @character.name %>)</em>
38-
<% end %>
39-
</p>
40-
<br /><br />
36+
<p class="center">
37+
<strong>Persona export for <%= @character.name %></strong>
38+
<% if user_signed_in? && @character.user_id == current_user.id %>
39+
<br />
40+
<em>(editable because you created <%= @character.name %>)</em>
41+
<% end %>
42+
</p>
43+
<br /><br />
4144

42-
<div class="input-field">
43-
<%= text_area_tag 'scenario', nil, disabled: false, style: 'min-height: 100px', placeholder: "Is there a specific scenario/context you want to have this conversation in?", class: 'materialize-textarea' %>
44-
<label for="scenario">Optional: Scenario</label>
45-
</div>
45+
<div class="input-field">
46+
<%= text_area_tag 'scenario', nil, disabled: false, style: 'min-height: 100px', placeholder: "Is there a specific scenario/context you want to have this conversation in?", class: 'materialize-textarea' %>
47+
<label for="scenario">Optional: Scenario</label>
48+
</div>
4649

47-
<div class="input-field">
48-
<%= text_area_tag 'char_greeting', @first_greeting, disabled: false, placeholder: "This will be the first thing your character says to you. It can be a simple greeting, or you can use it to set a specific topic, tone, or speaking style.", class: 'materialize-textarea' %>
49-
<label for="char_greeting">First greeting from <%= @character.name %></label>
50-
</div>
50+
<div class="input-field">
51+
<%= text_area_tag 'char_greeting', @first_greeting, disabled: false, placeholder: "This will be the first thing your character says to you. It can be a simple greeting, or you can use it to set a specific topic, tone, or speaking style.", class: 'materialize-textarea' %>
52+
<label for="char_greeting">First greeting from <%= @character.name %></label>
53+
</div>
5154

52-
<div class="input-field">
53-
<%= text_area_tag 'personality', @personality, disabled: false, class: 'materialize-textarea' %>
54-
<label for="personality">Personality</label>
55-
</div>
55+
<div class="input-field">
56+
<%= text_area_tag 'personality', @personality, disabled: false, class: 'materialize-textarea' %>
57+
<label for="personality">Brief personality</label>
58+
</div>
5659

57-
<div class="input-field">
58-
<%= text_area_tag 'description', @description, disabled: false, class: 'materialize-textarea' %>
59-
<label for="description">Description</label>
60-
</div>
60+
<div class="input-field">
61+
<%= text_area_tag 'description', @description, disabled: false, class: 'materialize-textarea' %>
62+
<label for="description">In-depth personality</label>
63+
</div>
6164

62-
<div class="input-field">
63-
<%= text_area_tag 'example_dialogue', nil, disabled: false, style: 'min-height: 100px', placeholder: "If you have any dialogue examples, quotes, or other phrases your character says, you can use this field to include them and adjust their speaking style closer to the examples. Write as little or as much as you'd like!", class: 'materialize-textarea' %>
64-
<label for="example_dialogue">Optional: More dialogue examples</label>
65-
</div>
65+
<div class="input-field">
66+
<%= text_area_tag 'example_dialogue', nil, disabled: false, style: 'min-height: 100px', placeholder: "If you have any dialogue examples, quotes, or other phrases your character says, you can use this field to include them and adjust their speaking style closer to the examples. Write as little or as much as you'd like!", class: 'materialize-textarea' %>
67+
<label for="example_dialogue">Optional: More dialogue examples</label>
68+
</div>
6669
</div>
6770

6871
<div class="card-panel">
6972
<div class="center">
70-
<strong>Note: OpenAI key required by OpenCharacters</strong>
73+
<strong>Note: An OpenAI API key is required by OpenCharacters</strong>
7174
</div>
7275

7376
<p>
74-
OpenCharacters uses this persona data with OpenAI's GPT models
75-
in an app that runs entirely in your browser, rather than being hosted or stored on any server.
76-
This means that you will need a valid OpenAI key to use this feature.
77+
OpenCharacters uses this persona data with OpenAI's GPT models
78+
in a web app that runs entirely in your browser, rather than being hosted or stored on any server.
79+
This means that you will need a valid OpenAI key to use this feature.
7780
</p>
7881
</div>
7982

8083
<br />
8184
<div class="center">
8285
<%= submit_tag "Chat with #{@character.name}", class: 'hoverable btn blue white-text' %>
83-
<span class="grey-text text-darken-1" style="margin-left: 1rem">using OpenCharacters</span>
86+
<span class="grey-text text-darken-1" style="margin-left: 0.5rem">using OpenCharacters</span>
8487
</div>
8588

8689
<% 10.times do %><br /><% end %>

config/routes.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@
2727
end
2828

2929
scope :talk do
30+
get '/', to: 'conversation#character_index', as: :conversation
3031
get '/to/:character_id', to: 'conversation#character_landing', as: :talk
31-
post '/export/:character_id', to: 'conversation#export', as: :export_character
32+
post '/export/:character_id', to: 'conversation#export', as: :export_character
3233
end
3334
end
3435

0 commit comments

Comments
 (0)