|
@@ -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"
|