Bladeren bron

Two user personalities (Odelia and Brian)

Allow img tag from media libraries
(avoid img hallucinations)

decrease hallucinated img tags
master
Nimrod Kerrett 1 jaar geleden
bovenliggende
commit
925bcc0b42
5 gewijzigde bestanden met toevoegingen van 29 en 25 verwijderingen
  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 Bestand weergeven

@@ -70,10 +70,12 @@ def file2json(path):
70 70
     "returns json string without line breaks and indent"
71 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 75
     json_schema = json.dumps(schema())
75 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 80
 load_dotenv()
79 81
 openai.organization = "org-GFWgNyt7NSKpCv6GhzXYZTpi"
@@ -87,8 +89,10 @@ Session(application)
87 89
 def home():
88 90
     is_initial = False
89 91
     if "messages" not in session:
92
+        if "user" not in session:
93
+            session["user"] = "odelia"  # terrible kludge
90 94
         session["messages"] = [
91
-          {"role": "system", "content": make_prompt()},
95
+          {"role": "system", "content": make_prompt(session["user"])},
92 96
           {"role": "assistant", "content": file2json("static/initial-chat.json")}
93 97
         ]
94 98
         session["history"] = []
@@ -127,11 +131,15 @@ def home():
127 131
     payload["history"] = list(reversed(session["history"][:-1]))
128 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 139
     for key in ["messages", "history"]:
133 140
         if key in session:
134 141
             del session[key]
142
+    session["user"] = user
135 143
     return redirect(url_for('home'))
136 144
 
137 145
 @application.get("/schema.json")
@@ -139,15 +147,6 @@ def schema():
139 147
     "return deref_schema of `chat.schema.json` file's content"
140 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 150
 @application.get("/slides")
152 151
 def slides():
153 152
     "Legacy multy-slide format"

+ 2
- 0
static/users/brian.txt Bestand weergeven

@@ -0,0 +1,2 @@
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 Bestand weergeven

@@ -0,0 +1,2 @@
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 Bestand weergeven

@@ -20,7 +20,8 @@
20 20
 	<body>
21 21
                 <div id="custom-nav">
22 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 25
                   <a href="/save" title="Save"><i class="fa fa-file-download">​</i></a>
25 26
                   <a href="/load" title="Load"><i class="fa fa-file-upload">​</i></a>
26 27
                 </div>
@@ -86,13 +87,7 @@
86 87
                             // open external links in new tab
87 88
                             $('.reveal a:not([href^="#"])').attr('target','_blank');
88 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 91
 			    // make all headers max-size
97 92
                             // $('.reveal h1, .reveal h2, .reveal h3').addClass('r-fit-text');
98 93
                             var enterSlide = function() {

+ 9
- 3
templates/prompt.txt Bestand weergeven

@@ -1,6 +1,6 @@
1 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 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,11 +15,17 @@ For example:
15 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 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 30
 2. It should also be valid according to the json-schema definition above:
25 31
 

Laden…
Annuleren
Opslaan