Quellcode durchsuchen

Don't start with a fixed chat

master
The Dod vor 1 Jahr
Ursprung
Commit
e712d02dcb
2 geänderte Dateien mit 15 neuen und 9 gelöschten Zeilen
  1. 12
    7
      app.py
  2. 3
    2
      static/initial-chat.json

+ 12
- 7
app.py Datei anzeigen

@@ -85,19 +85,24 @@ Session(application)
85 85
 
86 86
 @application.route("/", methods=['GET', 'POST'])
87 87
 def home():
88
+    is_initial = False
88 89
     if "messages" not in session:
89 90
         session["messages"] = [
90 91
           {"role": "system", "content": make_prompt()},
91 92
           {"role": "assistant", "content": file2json("static/initial-chat.json")}
92 93
         ]
93
-    if "history" not in session:
94 94
         session["history"] = []
95
-    if request.method=='POST':
96
-        prompt = request.form["prompt"].strip()
97
-        if prompt:
98
-            session["messages"] += [{"role": "user", "content": prompt}]
95
+        is_initial = True
96
+        prompt = ""
97
+    if request.method=='POST' or is_initial:
98
+        if is_initial:
99
+            session["messages"] += [{"role": "system", "content": "User has hit enter. You can begin."}]
99 100
         else:
100
-            session["messages"] += [{"role": "system", "content": "User has hit enter. Please continue."}]
101
+            prompt = request.form["prompt"].strip()
102
+            if prompt:
103
+                session["messages"] += [{"role": "user", "content": prompt}]
104
+            else:
105
+                session["messages"] += [{"role": "system", "content": "User has hit enter. Please continue."}]
101 106
         payload = None
102 107
         while not payload:
103 108
             reply = openai.ChatCompletion.create(model=os.environ["MODEL_NAME"], messages=session["messages"])
@@ -109,7 +114,7 @@ def home():
109 114
                 session["history"].append(payload)
110 115
             except Exception as e:
111 116
                 print(repr(e))
112
-                session["messages"] += [{"role": "system", "content": "reply was ignored because it's not a valid json. user is unaware. do not apologize to them"}]
117
+                session["messages"] += [{"role": "system", "content": "reply was ignored because it's not a valid json or doesn't comply with the schema. user is unaware. do not apologize to them"}]
113 118
             print("=====")
114 119
             print(reply["choices"][0]["message"]["content"])
115 120
             print("-----")

+ 3
- 2
static/initial-chat.json Datei anzeigen

@@ -1,6 +1,7 @@
1 1
 {
2 2
     "title": "Welcome",
3
-    "markdown": "Hello again.\n\nHow are you feeling right now? Can you share with me your emotions and thoughts? It's important for me to understand where you're at so that I can tailor our session accordingly.",
3
+    "markdown": "New ceremony.\n\nPlease hit enter when ready.",
4 4
     "bg_video": "static/media/bg-video/clouds1.mp4",
5
-    "use_soundtrack": false
5
+    "use_soundtrack": false,
6
+    "soundtrack": "static/media/audio/forest-with-small-river-birds-and-nature-field-recording-6735.mp3"
6 7
 }

Laden…
Abbrechen
Speichern