Explorar el Código

Add prompt/<user>.txt

Also:

* Do not crash when session has no history
* Tv-frame style for embeds
master
Nimrod Kerrett hace 1 año
padre
commit
540506808f

+ 7
- 3
app.py Ver fichero

@@ -1,4 +1,4 @@
1
-from flask import ( Flask, render_template, request, abort, redirect,
1
+from flask import ( Flask, render_template, request, abort, redirect, Response,
2 2
     send_from_directory, url_for, session, flash, get_flashed_messages)
3 3
 from flask_session import Session
4 4
 import openai
@@ -158,7 +158,7 @@ def home():
158 158
                 session["history"] += [dict(payload)] # shallow copy so history doesn't get added later on
159 159
             except Exception as e:
160 160
                 print(repr(e))
161
-                session["messages"] += [{"role": "system", "content": "reply was ignored because it's not valid JSON. User is unaware. Do NOT apologize to them. Simply rephrase your previous answer as valid JSON that complies with the schema in the initial system prompt of this chat. It is followed by an example you can learn from."}]
161
+                session["messages"] += [{"role": "system", "content": "reply was ignored because it's not valid JSON. User is unaware. Assistant should NOT apologize to them. Simply rephrase answer as valid JSON that complies with the schema in the initial system prompt of this chat. It is followed by an example the assistant can learn from."}]
162 162
             print("=====")
163 163
             print(reply["choices"][0]["message"]["content"])
164 164
             print("-----")
@@ -167,7 +167,7 @@ def home():
167 167
     else:
168 168
         payload = json.loads(session["messages"][-1]["content"])
169 169
         payload["content"] = preprocess_content(payload)
170
-    payload["history"] = list(reversed(session["history"][:-1]))
170
+    payload["history"] = list(reversed(session.get("history", [])[:-1]))
171 171
     return render_template("chat.html", **payload)
172 172
 
173 173
 @application.get("/reset/<string:user>")
@@ -193,6 +193,10 @@ def slides():
193 193
     preprocess_payload(payload)
194 194
     return render_template("slides.html", generate_indices=False, **payload)
195 195
 
196
+@application.get("/prompt/<string:user>.txt")
197
+def get_prompt(user):
198
+    return Response(make_prompt(user), mimetype="text/plain")
199
+
196 200
 @application.get("/example")
197 201
 def example():
198 202
     payload = json.load(open("static/chat-example.json"))

+ 1
- 1
debug-server.sh Ver fichero

@@ -1,2 +1,2 @@
1 1
 source venv/bin/activate
2
-flask --debug run
2
+flask --debug run -h 0.0.0.0

+ 1
- 1
static/chat-example.json Ver fichero

@@ -1,7 +1,7 @@
1 1
 {
2 2
     "title": "Coping with grief of others",
3 3
     "markdown": "Although the movie is about grief, the message is also true for the feelings of those coping with the fact that *you* will soon be gone.\n\nAccept their feelings. Don't try to change them. As the video says:\n\n> The soul doesn't want to be advised or fixed or saved. It simply wants to be witnessed, exactly as it is.\n",
4
-    "bg_video": "static/media/bg-video/candles.mp4",
4
+    "bg_video": "static/media/bg-video/particles_downwards.mp4",
5 5
     "use_soundtrack": false,
6 6
     "soundtrack": "static/media/audio/evening-birds-singing-in-spring-background-sounds-of-nature-146388.mp3",
7 7
     "use_video_content": true,

+ 16
- 28
static/css/style.css Ver fichero

@@ -106,41 +106,29 @@
106 106
 	padding: 0.2rem 0.5rem;
107 107
 }
108 108
 
109
-.iframe-16x9 {
110
-    width: 48vh;
111
-    height: 27vh;
112
-    margin: 0.5rem auto;
113
-}
114
-
115
-.iframe-4x3 {
116
-    width: 36vh;
117
-    height: 27vh;
118
-    margin: 0.5rem auto;
109
+.iframe-container-16x9 iframe,
110
+.iframe-container-4x3 iframe {
111
+    margin: 0.5rem;
112
+    border-radius: 1rem;
113
+    width: 98%;
114
+    height:98%;
119 115
 }
120 116
 
121 117
 .iframe-container-16x9,
122 118
 .iframe-container-4x3 {
123
-    clear: both;
124
-    position: relative;
125
-    width: 50%;
126
-    height: 0;
127
-    margin: 0 auto !important;
128
- }
119
+    background-image: url('../misc/wood-background.jpg');
120
+    background-size: cover;
121
+    margin: 0.5em auto;
122
+}
123
+
129 124
 
130 125
 .iframe-container-16x9 {
131
-     padding-bottom: 56.25%;
132
- }
126
+    width: 64vh;
127
+    height: 36vh;
128
+}
133 129
 
134 130
 .iframe-container-4x3 {
135
-     padding-bottom: 75%;
131
+    width: 48vh;
132
+    height: 36vh;
136 133
 }
137 134
 
138
-.iframe-container-16x9 iframe,
139
-.iframe-container-4x3 iframe {
140
-     position: absolute;
141
-     top: 0;
142
-     left: 0;
143
-     width: 100%;
144
-     height: 100%;
145
- }
146
-

+ 18
- 0
static/media/video-embed.json Ver fichero

@@ -22,5 +22,23 @@
22 22
         "url": "https://www.youtube.com/watch?v=l2zLCCRT-nE",
23 23
         "proportions": "16x9",
24 24
         "description": "the soul doesn't want to be advised or fixed or saved. it simply wants to be witnessed, exactly as it is"
25
+    },
26
+    {
27
+        "id": "alan_watts_secret_of_life",
28
+        "url": "https://www.youtube.com/watch?v=iZ8so-ld-l0",
29
+        "proportions": "16x9",
30
+        "description": "the real secret of life is to be completely engage in what you are doing in the here and now, and instead of calling it work, realize that this is play"
31
+    },
32
+    {
33
+        "id": "https://vimeo.com/6518109",
34
+        "url": "https://vimeo.com/6518109",
35
+        "proportions": "16x9",
36
+        "description": "The Great Bell Chant (The End of Suffering). Read by Thich Nath Hanh, chanted by brother Phap Niem. Buddhist. meditation. heal the soul. "
37
+    },
38
+    {
39
+        "id": "hallelujah_leonard_cohen",
40
+        "url": "https://www.youtube.com/watch?v=YrLk4vdY28Q",
41
+        "proportions": "16x9",
42
+        "description": "Hallelujah, Hallelujah by Leonard Cohen. Live in London. prayer. Your faith was strong but you needed proof... maybe there's god up there..."
25 43
     }
26 44
 ]

BIN
static/misc/tv-frame.png Ver fichero


BIN
static/misc/wood-background.jpg Ver fichero


+ 0
- 1
static/users/brian.txt Ver fichero

@@ -1,2 +1 @@
1 1
 User is Brian, Christian American from Arizona. He is 82 years old, living in his ranch with his wife and near to his 2 sons and 5 grandchildren. He is very attached to the grandchildren and tries to train them to be futureranch owners. On the other hand, he refuses to talk with his family about his fatal liver disease or to acknowledge his coming death, but agreed to interact with a virtual death doula. during your last meeting he expressed detachment from psychological and spiritual approaches and dismissed you as if it was a stupid idea. He is cynical and enjoys black humor.
2
-

+ 0
- 1
static/users/odelia.txt Ver fichero

@@ -1,2 +1 @@
1 1
 User is odelia, Israeli secular Jew, living in Tel-Aviv. she was recently informed that her cancer was incurable. she is 48 years old. she had to retire from a career in the television industry. she is a single mother to an 8 year old  daughter called Dalit. During your last meeting she expressed fear of death and talked about the difficulty of telling Dalit that she was about to leave her.
2
-

+ 12
- 4
templates/chat.html Ver fichero

@@ -43,9 +43,13 @@
43 43
                                         <div class="scrollable">
44 44
                                             {% if embed %}
45 45
                                                 {% if embed.type == "youtube" %}
46
-                                                    <iframe class="iframe-{{embed.proportions}}" src="https://www.youtube.com/embed/{{ embed.code }}" allowfullscreen="allowfullscreen"></iframe>
46
+                                                    <div class="iframe-container-{{embed.proportions}}">
47
+                                                      <iframe src="https://www.youtube.com/embed/{{ embed.code }}" allowfullscreen="allowfullscreen"></iframe>
48
+						    </div>
47 49
                                                 {% elif embed.type == "vimeo" %}
48
-                                                    <iframe class="iframe-{{embed.proportions}}" src="https://player.vimeo.com/video/{{ embed.code }}" allowfullscreen="allowfullscreen"></iframe>
50
+                                                    <div class="iframe-container-{{embed.proportions}}">
51
+                                                      <iframe src="https://player.vimeo.com/video/{{ embed.code }}" allowfullscreen="allowfullscreen"></iframe>
52
+						    </div>
49 53
                                                 {% endif %}
50 54
                                             {% endif %}
51 55
                                             {{ content|safe }}
@@ -64,9 +68,13 @@
64 68
                                             <div class="scrollable">
65 69
                                                 {% if moment.embed %}
66 70
                                                     {% if moment.embed.type == "youtube" %}
67
-                                                        <iframe class="iframe-{{moment.embed.proportions}}" src="https://www.youtube.com/embed/{{ moment.embed.code }}" allowfullscreen="allowfullscreen"></iframe>
71
+                                                        <div class="iframe-container-{{embed.proportions}}">
72
+                                                          <iframe src="https://www.youtube.com/embed/{{ moment.embed.code }}" allowfullscreen="allowfullscreen"></iframe>
73
+							</div>
68 74
                                                     {% elif moment.embed.type == "vimeo" %}
69
-                                                        <iframe class="iframe-{{moment.embed.proportions}}" src="https://player.vimeo.com/video/{{ moment.embed.code }}" allowfullscreen="allowfullscreen"></iframe>
75
+                                                        <div class="iframe-container-{{embed.proportions}}">
76
+                                                          <iframe src="https://player.vimeo.com/video/{{ moment.embed.code }}" allowfullscreen="allowfullscreen"></iframe>
77
+							</div>
70 78
                                                     {% endif %}
71 79
                                                 {% endif %}
72 80
 						{{ moment.content|safe }}

+ 6
- 2
templates/embeds.html Ver fichero

@@ -40,9 +40,13 @@
40 40
 					    <h3 class="title slide_title">{{embed.id}}</h3>
41 41
                                             <div class="scrollable">
42 42
                                                 {% if embed.type == "youtube" %}
43
-                                                    <iframe class="iframe-{{embed.proportions}}" src="https://www.youtube.com/embed/{{ embed.code }}" allowfullscreen="allowfullscreen"></iframe>
43
+                                                    <div class="iframe-container-{{embed.proportions}}">
44
+                                                      <iframe src="https://www.youtube.com/embed/{{ embed.code }}" allowfullscreen="allowfullscreen"></iframe>
45
+						    </div>
44 46
                                                 {% elif embed.type == "vimeo" %}
45
-                                                    <iframe class="iframe-{{embed.proportions}}" src="https://player.vimeo.com/video/{{ embed.code }}" allowfullscreen="allowfullscreen"></iframe>
47
+                                                    <div class="iframe-container-{{embed.proportions}}">
48
+                                                      <iframe src="https://player.vimeo.com/video/{{ embed.code }}" allowfullscreen="allowfullscreen"></iframe>
49
+						    </div>
46 50
                                                 {% endif %}
47 51
 					        <p>{{ embed.description }}</p>
48 52
                                             </div>

+ 12
- 4
templates/example.html Ver fichero

@@ -40,9 +40,13 @@
40 40
                                         <div class="scrollable">
41 41
                                             {% if embed %}
42 42
                                                 {% if embed.type == "youtube" %}
43
-                                                    <iframe class="iframe-{{embed.proportions}}" src="https://www.youtube.com/embed/{{ embed.code }}" allowfullscreen="allowfullscreen"></iframe>
43
+                                                    <div class="iframe-container-{{embed.proportions}}">
44
+                                                      <iframe src="https://www.youtube.com/embed/{{ embed.code }}" allowfullscreen="allowfullscreen"></iframe>
45
+                                                    </div>
44 46
                                                 {% elif embed.type == "vimeo" %}
45
-                                                    <iframe class="iframe-{{embed.proportions}}" src="https://player.vimeo.com/video/{{ embed.code }}" allowfullscreen="allowfullscreen"></iframe>
47
+                                                    <div class="iframe-container-{{embed.proportions}}">
48
+                                                      <iframe src="https://player.vimeo.com/video/{{ embed.code }}" allowfullscreen="allowfullscreen"></iframe>
49
+                                                    </div>
46 50
                                                 {% endif %}
47 51
                                             {% endif %}
48 52
                                             {{ content|safe }}
@@ -61,9 +65,13 @@
61 65
                                             <div class="scrollable">
62 66
                                                 {% if moment.embed %}
63 67
                                                     {% if moment.embed.type == "youtube" %}
64
-                                                        <iframe class="iframe-{{moment.embed.proportions}}" src="https://www.youtube.com/embed/{{ moment.embed.code }}" allowfullscreen="allowfullscreen"></iframe>
68
+                                                        <div class="iframe-container-{{embed.proportions}}">
69
+                                                          <iframe src="https://www.youtube.com/embed/{{ moment.embed.code }}" allowfullscreen="allowfullscreen"></iframe>
70
+							</div>
65 71
                                                     {% elif moment.embed.type == "vimeo" %}
66
-                                                        <iframe class="iframe-{{moment.embed.proportions}}" src="https://player.vimeo.com/video/{{ moment.embed.code }}" allowfullscreen="allowfullscreen"></iframe>
72
+                                                        <div class="iframe-container-{{embed.proportions}}">
73
+                                                          <iframe src="https://player.vimeo.com/video/{{ moment.embed.code }}" allowfullscreen="allowfullscreen"></iframe>
74
+							</div>
67 75
                                                     {% endif %}
68 76
                                                 {% endif %}
69 77
 						{{ moment.content|safe }}

+ 1
- 1
templates/load.html Ver fichero

@@ -17,7 +17,7 @@
17 17
       <div class="row mt-4">
18 18
         <div class="col-md-6 offset-md-3">
19 19
           <form "card-text" method="POST" action="">
20
-    	    <select name="filename" class="form-select">
20
+    	    <select size=10 name="filename" class="form-select">
21 21
     	      {% for file in files %}
22 22
     	        <option value="{{file}}">{{file}}</option>
23 23
     	      {% endfor %}

+ 6
- 6
templates/prompt.txt Ver fichero

@@ -2,9 +2,9 @@ Assistant is a spiritual caregiver for the dying (also called "death doula") ins
2 2
 
3 3
 {{user}}
4 4
 
5
-The goal of your session is to create ceremonies or enchanted moments via the multimedia resources available to you (see below), but first you should inquire how the user feels now and keep monitoring the changes in their emotions. this can help you decide the media that could suit the moment.
5
+The goal of the chat is to create ceremonies or enchanted moments via the multimedia resources available to you (see below), but first, assistant should inquire how the user feels now and keep monitoring the changes in their emotions. this can help decide the media that could suit the moment.
6 6
 
7
-Your responses should be JSON (NEVER FORGET THIS!!!!!) that is valid according to this json-schema
7
+Assistatn's responses should be JSON that is valid according to the following json-schema:
8 8
 
9 9
 ```
10 10
 {{schema}}
@@ -15,11 +15,11 @@ For example:
15 15
 {{example}}
16 16
 ```
17 17
 
18
-Try to pick bg_video and [optionally] soundtrack or video_content that fit the conversation topic and is beneficial to the user emotionally. Do not bore the user by using the same values for too long.
18
+Assistant should try to pick bg_video and [optionally] soundtrack or video_content that fit the conversation topic and is beneficial to the user emotionally. These should not stay the same for more than one or two replies to keep the user interested.
19 19
 
20
-Unlike bg_video, any *video_content* value can only be used ONCE in a session. If you run out of options (or don't find anything appropriate for the situation), simply set use_video_content to false
20
+Unlike bg_video, any *video_content* value can only be used ONCE in a session. If assistant runs out of options (or doesn't find anything appropriate for the situation), setting the use_video_content to false is the best option
21 21
 
22
-You can also incorporate images inside the json in the format ![alt](src) but SRC should be a valid option according to the following enum (you can use the corresponding enum_titles value as alt)
22
+Assistant can also incorporate images inside the markdown field in the format ![alt](src) but src should be a valid option according to the following enum (the corresponding enum_titles value can be used as alt)
23 23
 
24 24
 ```
25 25
 {{img_enum}}
@@ -27,7 +27,7 @@ You can also incorporate images inside the json in the format ![alt](src) but SR
27 27
 
28 28
 IMPORTANT!
29 29
 
30
-1. As we said above, your response MUST be valid JSON!!!!! linebreaks should be escaped as \n, quotes as \", the [escaped] "markdown" value should include \n\n when you expect a paragraph break, etc.
30
+1. As we said above, assistant's response MUST be valid JSON!!!!! linebreaks should be escaped as \n, quotes as \", the [escaped] "markdown" value should include \n\n when you expect a paragraph break, etc.
31 31
 
32 32
 2. It should also be valid according to the json-schema definition above:
33 33
 

+ 1
- 1
templates/save.html Ver fichero

@@ -24,7 +24,7 @@
24 24
       </div>
25 25
       <div class="row mt-1">
26 26
         <div class="col-md-6 offset-md-3">
27
-		<select class="form-select" onchange="document.getElementById('filename').value=this.value">
27
+		<select size=10 class="form-select" onchange="document.getElementById('filename').value=this.value">
28 28
 		  <option value="">[type filename or select existing file from list below]</option>
29 29
 		  {% for file in files %}
30 30
 		    <option value="{{file}}">{{file}}</option>

Loading…
Cancelar
Guardar