Update app.py
Browse files
app.py
CHANGED
@@ -15,6 +15,10 @@ defaultMsg = os.environ['defaultMsg']
|
|
15 |
|
16 |
mod = 3;
|
17 |
|
|
|
|
|
|
|
|
|
18 |
def trimMessages(messages):
|
19 |
# Assuming messages is an array of objects with "role" and "content" properties
|
20 |
content = {}
|
@@ -32,14 +36,22 @@ def trimMessages(messages):
|
|
32 |
|
33 |
def getChooseRole(msg):
|
34 |
start_index = msg.index("As a") + len("As a")
|
35 |
-
|
36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
|
38 |
def getChooseClass(msg):
|
39 |
full = getChooseRole(msg)
|
|
|
40 |
start_index = full.index(" ") + len(" ")
|
41 |
end_index = msg.index(",")
|
42 |
-
return full[start_index:] + full[:end_index]
|
43 |
|
44 |
def chatbot(input, messages):
|
45 |
messages = messages or [{"role": "system", "content": initMsg}]
|
@@ -63,10 +75,16 @@ def chatbot(input, messages):
|
|
63 |
logging.info("AI Reply:"+reply)
|
64 |
ans = ""
|
65 |
if len(messages) == 2:
|
66 |
-
|
|
|
|
|
|
|
67 |
logging.info("ChooseRole:"+ans)
|
68 |
if len(messages) == 4:
|
69 |
-
|
|
|
|
|
|
|
70 |
logging.info("ChooseClass:"+ans)
|
71 |
messages.append({"role": "assistant", "content": ans})
|
72 |
return reply, printMessages(messages), messages
|
|
|
15 |
|
16 |
mod = 3;
|
17 |
|
18 |
+
def localVar(lv):
|
19 |
+
lv = lv or {"race":"", "cls":""}
|
20 |
+
return lv
|
21 |
+
|
22 |
def trimMessages(messages):
|
23 |
# Assuming messages is an array of objects with "role" and "content" properties
|
24 |
content = {}
|
|
|
36 |
|
37 |
def getChooseRole(msg):
|
38 |
start_index = msg.index("As a") + len("As a")
|
39 |
+
if start_index >= 0:
|
40 |
+
end_index = msg.index(",")
|
41 |
+
str = trim(msg[start_index:] + msg[:end_index])
|
42 |
+
if str.lower() = "dm"
|
43 |
+
return ""
|
44 |
+
else:
|
45 |
+
return str
|
46 |
+
else:
|
47 |
+
return ""
|
48 |
|
49 |
def getChooseClass(msg):
|
50 |
full = getChooseRole(msg)
|
51 |
+
if
|
52 |
start_index = full.index(" ") + len(" ")
|
53 |
end_index = msg.index(",")
|
54 |
+
return trim(full[start_index:] + full[:end_index])
|
55 |
|
56 |
def chatbot(input, messages):
|
57 |
messages = messages or [{"role": "system", "content": initMsg}]
|
|
|
75 |
logging.info("AI Reply:"+reply)
|
76 |
ans = ""
|
77 |
if len(messages) == 2:
|
78 |
+
lv.race = getChooseRole(reply)
|
79 |
+
lv.cls = ""
|
80 |
+
lv = localVar(lv)
|
81 |
+
ans = "I choose "+ lv.race +" as my race." + classAsk
|
82 |
logging.info("ChooseRole:"+ans)
|
83 |
if len(messages) == 4:
|
84 |
+
lv = localVar(lv)
|
85 |
+
lv.cls = getChooseClass(reply)
|
86 |
+
lv = localVar(lv)
|
87 |
+
ans = "My Race is "+ lv.race +",I choose "+ lv.cls +" as my class." + classAns
|
88 |
logging.info("ChooseClass:"+ans)
|
89 |
messages.append({"role": "assistant", "content": ans})
|
90 |
return reply, printMessages(messages), messages
|