Update app.py
Browse files
app.py
CHANGED
|
@@ -63,25 +63,15 @@ def getChooseClass(msg):
|
|
| 63 |
else:
|
| 64 |
return ""
|
| 65 |
|
| 66 |
-
def chatbot(race, cls, input, localvar):
|
| 67 |
#messages = messages or [{"role": "system", "content": initMsg}]
|
| 68 |
localvar = localvar or {"messages": [{"role": "system", "content": "I choose as "+ race + " "+ cls +" in D&D world.\n" + initMsg}], "race": race, "class": cls, "status":""}
|
| 69 |
messages = localvar['messages']
|
| 70 |
-
#if len(messages) == 1:
|
| 71 |
-
|
| 72 |
-
#memory = trimMessages(messages)
|
| 73 |
-
#logging.info("put memory:"+printMessages(memory))
|
| 74 |
-
#chat = openai.ChatCompletion.create(
|
| 75 |
-
# model="gpt-3.5-turbo", messages=memory,
|
| 76 |
-
# max_tokens=1048,n=1,temperature=0.5,
|
| 77 |
-
#)
|
| 78 |
-
#logging.info("put memory return:"+chat.choices[0].message.content)
|
| 79 |
-
|
| 80 |
if input:
|
| 81 |
-
if len(messages) == 1:
|
| 82 |
-
|
| 83 |
-
else:
|
| 84 |
-
|
| 85 |
chat = openai.ChatCompletion.create(
|
| 86 |
model="gpt-3.5-turbo", messages=messages[-2:],
|
| 87 |
max_tokens=2048,n=1,temperature=0.5,
|
|
@@ -100,9 +90,9 @@ def printMessages(messages):
|
|
| 100 |
logging.info("messages:"+msg_string)
|
| 101 |
return msg_string
|
| 102 |
|
| 103 |
-
app = gr.Interface(fn=chatbot, inputs=[gr.Dropdown(["Orc", "Human", "Elf", "Dwarf", "Halfling", "Goliath", "Dragonborn"], label="Race", info="please choose your race:"),
|
| 104 |
-
gr.Dropdown(["Warrior", "Mage", "Priest", "Assassin", "Thief", "Paladin", "Archer", "Guardian"], label="Class", info="please choose the name of the class you wish to play as:"),
|
| 105 |
-
gr.Textbox(lines=7, label="You ask and answer questions below", placeholder="
|
| 106 |
outputs=[gr.Textbox(label="DND Game Reply", placeholder="Waiting for you start..."), gr.Textbox(label="History"), "state"], title="DND Game",#, gr.Textbox(label="History"),
|
| 107 |
description="DND Game",theme="compact")
|
| 108 |
app.launch(share=False)
|
|
|
|
| 63 |
else:
|
| 64 |
return ""
|
| 65 |
|
| 66 |
+
def chatbot(race, cls, input, localvar):
|
| 67 |
#messages = messages or [{"role": "system", "content": initMsg}]
|
| 68 |
localvar = localvar or {"messages": [{"role": "system", "content": "I choose as "+ race + " "+ cls +" in D&D world.\n" + initMsg}], "race": race, "class": cls, "status":""}
|
| 69 |
messages = localvar['messages']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
if input:
|
| 71 |
+
#if len(messages) == 1:
|
| 72 |
+
# messages.append({"role": "user", "content": input})
|
| 73 |
+
#else:
|
| 74 |
+
messages.append({"role": "user", "content": defaultMsg + "(I am an "+race+" "+cls+")( My Current status is as follows :" + localvar['status'] + ") " + defaultMsgEnd + ". \n" + input})
|
| 75 |
chat = openai.ChatCompletion.create(
|
| 76 |
model="gpt-3.5-turbo", messages=messages[-2:],
|
| 77 |
max_tokens=2048,n=1,temperature=0.5,
|
|
|
|
| 90 |
logging.info("messages:"+msg_string)
|
| 91 |
return msg_string
|
| 92 |
|
| 93 |
+
app = gr.Interface(fn=chatbot, inputs=[gr.Dropdown(["Orc", "Human", "Elf", "Dwarf", "Halfling", "Goliath", "Dragonborn"], value="Orc", label="Race", info="please choose your race:"),
|
| 94 |
+
gr.Dropdown(["Warrior", "Mage", "Priest", "Assassin", "Thief", "Paladin", "Archer", "Guardian"], value="Warrior", label="Class", info="please choose the name of the class you wish to play as:"),
|
| 95 |
+
gr.Textbox(lines=7, label="You ask and answer questions below", placeholder="press submit button to play"), "state"], #Type word 'start game'
|
| 96 |
outputs=[gr.Textbox(label="DND Game Reply", placeholder="Waiting for you start..."), gr.Textbox(label="History"), "state"], title="DND Game",#, gr.Textbox(label="History"),
|
| 97 |
description="DND Game",theme="compact")
|
| 98 |
app.launch(share=False)
|