Update app.py
Browse files
app.py
CHANGED
@@ -30,8 +30,19 @@ def trimMessages(messages):
|
|
30 |
messages.append({"role": "assistant", "content": content})
|
31 |
return messages
|
32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
def chatbot(input, messages):
|
34 |
-
messages = messages or [{"role": "system", "content":
|
35 |
if len(messages) == 1:
|
36 |
|
37 |
memory = trimMessages(messages)
|
@@ -49,7 +60,15 @@ def chatbot(input, messages):
|
|
49 |
max_tokens=2048,n=1,temperature=0.5,
|
50 |
)
|
51 |
reply = chat.choices[0].message.content
|
52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
return reply, messages
|
54 |
|
55 |
def printMessages(messages):
|
@@ -59,6 +78,6 @@ def printMessages(messages):
|
|
59 |
return msg_string
|
60 |
|
61 |
app = gr.Interface(fn=chatbot, inputs=[gr.Textbox(lines=7, label="You ask and answer questions below"), "state"],
|
62 |
-
outputs=[gr.Textbox(label="DND Game Reply", placeholder=
|
63 |
description="DND Game",theme="compact")
|
64 |
app.launch(share=False)
|
|
|
30 |
messages.append({"role": "assistant", "content": content})
|
31 |
return messages
|
32 |
|
33 |
+
def getChooseRole(msg):
|
34 |
+
start_index = msg.index("As an ") + len("As an ")
|
35 |
+
end_index = msg.index(",")
|
36 |
+
return msg[start_index:] + msg[:start_index]
|
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[:start_index]
|
43 |
+
|
44 |
def chatbot(input, messages):
|
45 |
+
messages = messages or [{"role": "system", "content": initMsg}]
|
46 |
if len(messages) == 1:
|
47 |
|
48 |
memory = trimMessages(messages)
|
|
|
60 |
max_tokens=2048,n=1,temperature=0.5,
|
61 |
)
|
62 |
reply = chat.choices[0].message.content
|
63 |
+
|
64 |
+
ans = ""
|
65 |
+
if len(messages) == 3:
|
66 |
+
ans = "I choose "+ getChooseRole(reply) +" as my race." + classAsk
|
67 |
+
logging.info("ChooseRole:"+ans)
|
68 |
+
if len(messages) == 5:
|
69 |
+
ans = "My Race is ,I choose "+ getChooseClass(reply) +" as my class." + classAns
|
70 |
+
logging.info("ChooseClass:"+ans)
|
71 |
+
messages.append({"role": "assistant", "content": ans})
|
72 |
return reply, messages
|
73 |
|
74 |
def printMessages(messages):
|
|
|
78 |
return msg_string
|
79 |
|
80 |
app = gr.Interface(fn=chatbot, inputs=[gr.Textbox(lines=7, label="You ask and answer questions below"), "state"],
|
81 |
+
outputs=[gr.Textbox(label="DND Game Reply", placeholder=roleAns), "state"], title="DND Game",#, gr.Textbox(label="History"),
|
82 |
description="DND Game",theme="compact")
|
83 |
app.launch(share=False)
|