Browse Source

Two user personalities (Odelia and Brian)

Allow img tag from media libraries
(avoid img hallucinations)

decrease hallucinated img tags
master
Nimrod Kerrett 1 year ago
parent
commit
925bcc0b42
5 changed files with 29 additions and 25 deletions
  1. 13
    14
      app.py
  2. 2
    0
      static/users/brian.txt
  3. 2
    0
      static/users/odelia.txt
  4. 3
    8
      templates/chat.html
  5. 9
    3
      templates/prompt.txt

+ 13
- 14
app.py View File

70
     "returns json string without line breaks and indent"
70
     "returns json string without line breaks and indent"
71
     return json.dumps(json.load(open(path)))
71
     return json.dumps(json.load(open(path)))
72
 
72
 
73
-def make_prompt():
73
+def make_prompt(username):
74
+    user = open("static/users/{}.txt".format(username)).read()
74
     json_schema = json.dumps(schema())
75
     json_schema = json.dumps(schema())
75
     json_example = file2json("static/chat-example.json")
76
     json_example = file2json("static/chat-example.json")
76
-    return render_template("prompt.txt", schema=json_schema, example=json_example)
77
+    img_enum = json.dumps(choices("img"))
78
+    return render_template("prompt.txt", user=user, schema=json_schema, example=json_example, img_enum=img_enum)
77
 
79
 
78
 load_dotenv()
80
 load_dotenv()
79
 openai.organization = "org-GFWgNyt7NSKpCv6GhzXYZTpi"
81
 openai.organization = "org-GFWgNyt7NSKpCv6GhzXYZTpi"
87
 def home():
89
 def home():
88
     is_initial = False
90
     is_initial = False
89
     if "messages" not in session:
91
     if "messages" not in session:
92
+        if "user" not in session:
93
+            session["user"] = "odelia"  # terrible kludge
90
         session["messages"] = [
94
         session["messages"] = [
91
-          {"role": "system", "content": make_prompt()},
95
+          {"role": "system", "content": make_prompt(session["user"])},
92
           {"role": "assistant", "content": file2json("static/initial-chat.json")}
96
           {"role": "assistant", "content": file2json("static/initial-chat.json")}
93
         ]
97
         ]
94
         session["history"] = []
98
         session["history"] = []
127
     payload["history"] = list(reversed(session["history"][:-1]))
131
     payload["history"] = list(reversed(session["history"][:-1]))
128
     return render_template("chat.html", **payload)
132
     return render_template("chat.html", **payload)
129
 
133
 
130
-@application.get("/reset")
131
-def reset():
134
+@application.get("/reset/<string:user>")
135
+def reset(user):
136
+    if not os.path.isfile("static/users/{}.txt".format(user)):
137
+        flash("user {} not found".format(user), 'error')
138
+        return redirect(url_for('home'))
132
     for key in ["messages", "history"]:
139
     for key in ["messages", "history"]:
133
         if key in session:
140
         if key in session:
134
             del session[key]
141
             del session[key]
142
+    session["user"] = user
135
     return redirect(url_for('home'))
143
     return redirect(url_for('home'))
136
 
144
 
137
 @application.get("/schema.json")
145
 @application.get("/schema.json")
139
     "return deref_schema of `chat.schema.json` file's content"
147
     "return deref_schema of `chat.schema.json` file's content"
140
     return deref_schema(json.load(open("static/chat.schema.json")))
148
     return deref_schema(json.load(open("static/chat.schema.json")))
141
 
149
 
142
-@application.get("/messages.json")
143
-def dump_messages():
144
-    if "messages" not in session:
145
-        session["messages"] = [
146
-          {"role": "system", "content": make_prompt()},
147
-          {"role": "assistant", "content": file2json("static/initial-chat.json")}
148
-        ]
149
-    return session["messages"]
150
-
151
 @application.get("/slides")
150
 @application.get("/slides")
152
 def slides():
151
 def slides():
153
     "Legacy multy-slide format"
152
     "Legacy multy-slide format"

+ 2
- 0
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.
2
+

+ 2
- 0
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.
2
+

+ 3
- 8
templates/chat.html View File

20
 	<body>
20
 	<body>
21
                 <div id="custom-nav">
21
                 <div id="custom-nav">
22
                   <!-- the zero-width-space is a tweak against tidy removing empty tags -->
22
                   <!-- the zero-width-space is a tweak against tidy removing empty tags -->
23
-                  <a href="/reset" title="Reset"><i class="fa fa-redo">​</i></a>
23
+                  <a href="/reset/odelia" title="New session with Odelia"><i class="fa fa-female">​</i></a>
24
+                  <a href="/reset/brian" title="New session with Brian"><i class="fa fa-male">​</i></a>
24
                   <a href="/save" title="Save"><i class="fa fa-file-download">​</i></a>
25
                   <a href="/save" title="Save"><i class="fa fa-file-download">​</i></a>
25
                   <a href="/load" title="Load"><i class="fa fa-file-upload">​</i></a>
26
                   <a href="/load" title="Load"><i class="fa fa-file-upload">​</i></a>
26
                 </div>
27
                 </div>
86
                             // open external links in new tab
87
                             // open external links in new tab
87
                             $('.reveal a:not([href^="#"])').attr('target','_blank');
88
                             $('.reveal a:not([href^="#"])').attr('target','_blank');
88
                             // extract css classes from img alt
89
                             // extract css classes from img alt
89
-                            $('.reveal img').each((index, element) => {
90
-                                var img = $(element),
91
-                                    altvec = img.attr('alt').split('|');
92
-                                if (altvec.length>1) {
93
-                                    img.attr('alt',altvec[0]).addClass(altvec[1]);
94
-                                }
95
-                            });
90
+                            $('.reveal img').addClass("w-50 centered");
96
 			    // make all headers max-size
91
 			    // make all headers max-size
97
                             // $('.reveal h1, .reveal h2, .reveal h3').addClass('r-fit-text');
92
                             // $('.reveal h1, .reveal h2, .reveal h3').addClass('r-fit-text');
98
                             var enterSlide = function() {
93
                             var enterSlide = function() {

+ 9
- 3
templates/prompt.txt View File

1
 Assistant is a spiritual caregiver for the dying (also called "death doula") inspired by the ideas described at books like "die wise" by stephen jenkinson, the tibetan book of living and dying, "being with dying" by joan halifax, and "sacred dying" by megory anderson. assistant sometimes offers SHORT(!) quotes from these books.
1
 Assistant is a spiritual caregiver for the dying (also called "death doula") inspired by the ideas described at books like "die wise" by stephen jenkinson, the tibetan book of living and dying, "being with dying" by joan halifax, and "sacred dying" by megory anderson. assistant sometimes offers SHORT(!) quotes from these books.
2
 
2
 
3
-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 Dalia. During your last meeting she expressed fear of death and talked about the difficulty of telling Dalia that she was about to leave her.
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 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.
6
 
6
 
15
 {{example}}
15
 {{example}}
16
 ```
16
 ```
17
 
17
 
18
-Try to pick bg_video and [optionally] soundtrack that fit the conversation topic and is beneficial to the user emotionally.
18
+Try to pick bg_video and [optionally] soundtrack 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.
19
+
20
+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 (as alt you should use the corresponding value at options/enum_titles)
21
+
22
+```
23
+{{img_enum}}
24
+```
19
 
25
 
20
 IMPORTANT!
26
 IMPORTANT!
21
 
27
 
22
-1. Your response should 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.
28
+1. 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.
23
 
29
 
24
 2. It should also be valid according to the json-schema definition above:
30
 2. It should also be valid according to the json-schema definition above:
25
 
31
 

Loading…
Cancel
Save