Browse Source

Add prompt/<user>.txt

Also:

* Do not crash when session has no history
* Tv-frame style for embeds
master
Nimrod Kerrett 1 year ago
parent
commit
540506808f

+ 7
- 3
app.py View File

1
-from flask import ( Flask, render_template, request, abort, redirect,
1
+from flask import ( Flask, render_template, request, abort, redirect, Response,
2
     send_from_directory, url_for, session, flash, get_flashed_messages)
2
     send_from_directory, url_for, session, flash, get_flashed_messages)
3
 from flask_session import Session
3
 from flask_session import Session
4
 import openai
4
 import openai
158
                 session["history"] += [dict(payload)] # shallow copy so history doesn't get added later on
158
                 session["history"] += [dict(payload)] # shallow copy so history doesn't get added later on
159
             except Exception as e:
159
             except Exception as e:
160
                 print(repr(e))
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
             print("=====")
162
             print("=====")
163
             print(reply["choices"][0]["message"]["content"])
163
             print(reply["choices"][0]["message"]["content"])
164
             print("-----")
164
             print("-----")
167
     else:
167
     else:
168
         payload = json.loads(session["messages"][-1]["content"])
168
         payload = json.loads(session["messages"][-1]["content"])
169
         payload["content"] = preprocess_content(payload)
169
         payload["content"] = preprocess_content(payload)
170
-    payload["history"] = list(reversed(session["history"][:-1]))
170
+    payload["history"] = list(reversed(session.get("history", [])[:-1]))
171
     return render_template("chat.html", **payload)
171
     return render_template("chat.html", **payload)
172
 
172
 
173
 @application.get("/reset/<string:user>")
173
 @application.get("/reset/<string:user>")
193
     preprocess_payload(payload)
193
     preprocess_payload(payload)
194
     return render_template("slides.html", generate_indices=False, **payload)
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
 @application.get("/example")
200
 @application.get("/example")
197
 def example():
201
 def example():
198
     payload = json.load(open("static/chat-example.json"))
202
     payload = json.load(open("static/chat-example.json"))

+ 1
- 1
debug-server.sh View File

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

+ 1
- 1
static/chat-example.json View File

1
 {
1
 {
2
     "title": "Coping with grief of others",
2
     "title": "Coping with grief of others",
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",
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
     "use_soundtrack": false,
5
     "use_soundtrack": false,
6
     "soundtrack": "static/media/audio/evening-birds-singing-in-spring-background-sounds-of-nature-146388.mp3",
6
     "soundtrack": "static/media/audio/evening-birds-singing-in-spring-background-sounds-of-nature-146388.mp3",
7
     "use_video_content": true,
7
     "use_video_content": true,

+ 16
- 28
static/css/style.css View File

106
 	padding: 0.2rem 0.5rem;
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
 .iframe-container-16x9,
117
 .iframe-container-16x9,
122
 .iframe-container-4x3 {
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
 .iframe-container-16x9 {
125
 .iframe-container-16x9 {
131
-     padding-bottom: 56.25%;
132
- }
126
+    width: 64vh;
127
+    height: 36vh;
128
+}
133
 
129
 
134
 .iframe-container-4x3 {
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 View File

22
         "url": "https://www.youtube.com/watch?v=l2zLCCRT-nE",
22
         "url": "https://www.youtube.com/watch?v=l2zLCCRT-nE",
23
         "proportions": "16x9",
23
         "proportions": "16x9",
24
         "description": "the soul doesn't want to be advised or fixed or saved. it simply wants to be witnessed, exactly as it is"
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 View File


BIN
static/misc/wood-background.jpg View File


+ 0
- 1
static/users/brian.txt View File

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.
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 View File

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.
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 View File

43
                                         <div class="scrollable">
43
                                         <div class="scrollable">
44
                                             {% if embed %}
44
                                             {% if embed %}
45
                                                 {% if embed.type == "youtube" %}
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
                                                 {% elif embed.type == "vimeo" %}
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
                                                 {% endif %}
53
                                                 {% endif %}
50
                                             {% endif %}
54
                                             {% endif %}
51
                                             {{ content|safe }}
55
                                             {{ content|safe }}
64
                                             <div class="scrollable">
68
                                             <div class="scrollable">
65
                                                 {% if moment.embed %}
69
                                                 {% if moment.embed %}
66
                                                     {% if moment.embed.type == "youtube" %}
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
                                                     {% elif moment.embed.type == "vimeo" %}
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
                                                     {% endif %}
78
                                                     {% endif %}
71
                                                 {% endif %}
79
                                                 {% endif %}
72
 						{{ moment.content|safe }}
80
 						{{ moment.content|safe }}

+ 6
- 2
templates/embeds.html View File

40
 					    <h3 class="title slide_title">{{embed.id}}</h3>
40
 					    <h3 class="title slide_title">{{embed.id}}</h3>
41
                                             <div class="scrollable">
41
                                             <div class="scrollable">
42
                                                 {% if embed.type == "youtube" %}
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
                                                 {% elif embed.type == "vimeo" %}
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
                                                 {% endif %}
50
                                                 {% endif %}
47
 					        <p>{{ embed.description }}</p>
51
 					        <p>{{ embed.description }}</p>
48
                                             </div>
52
                                             </div>

+ 12
- 4
templates/example.html View File

40
                                         <div class="scrollable">
40
                                         <div class="scrollable">
41
                                             {% if embed %}
41
                                             {% if embed %}
42
                                                 {% if embed.type == "youtube" %}
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
                                                 {% elif embed.type == "vimeo" %}
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
                                                 {% endif %}
50
                                                 {% endif %}
47
                                             {% endif %}
51
                                             {% endif %}
48
                                             {{ content|safe }}
52
                                             {{ content|safe }}
61
                                             <div class="scrollable">
65
                                             <div class="scrollable">
62
                                                 {% if moment.embed %}
66
                                                 {% if moment.embed %}
63
                                                     {% if moment.embed.type == "youtube" %}
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
                                                     {% elif moment.embed.type == "vimeo" %}
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
                                                     {% endif %}
75
                                                     {% endif %}
68
                                                 {% endif %}
76
                                                 {% endif %}
69
 						{{ moment.content|safe }}
77
 						{{ moment.content|safe }}

+ 1
- 1
templates/load.html View File

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

+ 6
- 6
templates/prompt.txt View File

2
 
2
 
3
 {{user}}
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
 {{schema}}
10
 {{schema}}
15
 {{example}}
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
 {{img_enum}}
25
 {{img_enum}}
27
 
27
 
28
 IMPORTANT!
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
 2. It should also be valid according to the json-schema definition above:
32
 2. It should also be valid according to the json-schema definition above:
33
 
33
 

+ 1
- 1
templates/save.html View File

24
       </div>
24
       </div>
25
       <div class="row mt-1">
25
       <div class="row mt-1">
26
         <div class="col-md-6 offset-md-3">
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
 		  <option value="">[type filename or select existing file from list below]</option>
28
 		  <option value="">[type filename or select existing file from list below]</option>
29
 		  {% for file in files %}
29
 		  {% for file in files %}
30
 		    <option value="{{file}}">{{file}}</option>
30
 		    <option value="{{file}}">{{file}}</option>

Loading…
Cancel
Save