Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -155,6 +155,7 @@ def run_action1(message, history):
|
|
| 155 |
def main_loop1(message, history):
|
| 156 |
return run_action(message, history)
|
| 157 |
|
|
|
|
| 158 |
# Function to process user input and actions
|
| 159 |
def run_action(message, history):
|
| 160 |
global game_state, game_running # Access the global game state and game status
|
|
@@ -162,29 +163,26 @@ def run_action(message, history):
|
|
| 162 |
if history is None:
|
| 163 |
history = [] # Initialize history if it's None
|
| 164 |
|
| 165 |
-
# Append user's message to history
|
| 166 |
-
history.append({"role": "user", "content": message})
|
| 167 |
-
|
| 168 |
if not game_running:
|
| 169 |
response = "The game has ended. Type 'restart the game' to play again."
|
| 170 |
-
history.append(
|
| 171 |
return history
|
| 172 |
|
| 173 |
if message.lower() == "start game":
|
| 174 |
response = game_state["start"]
|
| 175 |
-
history.append(
|
| 176 |
return history
|
| 177 |
|
| 178 |
if message.lower() == "restart the game":
|
| 179 |
game_state = initialize_game_state()
|
| 180 |
response = "Game restarted! " + game_state["start"]
|
| 181 |
-
history.append(
|
| 182 |
return history
|
| 183 |
|
| 184 |
if message.lower() == "exit":
|
| 185 |
game_running = False
|
| 186 |
response = "The game has ended. Type 'restart the game' to play again."
|
| 187 |
-
history.append(
|
| 188 |
return history
|
| 189 |
|
| 190 |
# Prepare the system prompt
|
|
@@ -208,9 +206,9 @@ def run_action(message, history):
|
|
| 208 |
{"role": "user", "content": world_info},
|
| 209 |
]
|
| 210 |
|
| 211 |
-
for
|
| 212 |
-
|
| 213 |
-
|
| 214 |
|
| 215 |
# Add the user's current action
|
| 216 |
messages.append({"role": "user", "content": message})
|
|
@@ -223,8 +221,8 @@ def run_action(message, history):
|
|
| 223 |
|
| 224 |
response = model_output.choices[0].message.content
|
| 225 |
|
| 226 |
-
# Append the assistant's response to history
|
| 227 |
-
history.append(
|
| 228 |
|
| 229 |
return history
|
| 230 |
|
|
@@ -232,6 +230,13 @@ def run_action(message, history):
|
|
| 232 |
def main_loop(message, history):
|
| 233 |
return run_action(message, history)
|
| 234 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 235 |
demo = gr.ChatInterface(
|
| 236 |
main_loop,
|
| 237 |
chatbot=gr.Chatbot(
|
|
|
|
| 155 |
def main_loop1(message, history):
|
| 156 |
return run_action(message, history)
|
| 157 |
|
| 158 |
+
|
| 159 |
# Function to process user input and actions
|
| 160 |
def run_action(message, history):
|
| 161 |
global game_state, game_running # Access the global game state and game status
|
|
|
|
| 163 |
if history is None:
|
| 164 |
history = [] # Initialize history if it's None
|
| 165 |
|
|
|
|
|
|
|
|
|
|
| 166 |
if not game_running:
|
| 167 |
response = "The game has ended. Type 'restart the game' to play again."
|
| 168 |
+
history.append((message, response))
|
| 169 |
return history
|
| 170 |
|
| 171 |
if message.lower() == "start game":
|
| 172 |
response = game_state["start"]
|
| 173 |
+
history.append((message, response))
|
| 174 |
return history
|
| 175 |
|
| 176 |
if message.lower() == "restart the game":
|
| 177 |
game_state = initialize_game_state()
|
| 178 |
response = "Game restarted! " + game_state["start"]
|
| 179 |
+
history.append((message, response))
|
| 180 |
return history
|
| 181 |
|
| 182 |
if message.lower() == "exit":
|
| 183 |
game_running = False
|
| 184 |
response = "The game has ended. Type 'restart the game' to play again."
|
| 185 |
+
history.append((message, response))
|
| 186 |
return history
|
| 187 |
|
| 188 |
# Prepare the system prompt
|
|
|
|
| 206 |
{"role": "user", "content": world_info},
|
| 207 |
]
|
| 208 |
|
| 209 |
+
for user_input, assistant_response in history:
|
| 210 |
+
messages.append({"role": "user", "content": user_input})
|
| 211 |
+
messages.append({"role": "assistant", "content": assistant_response})
|
| 212 |
|
| 213 |
# Add the user's current action
|
| 214 |
messages.append({"role": "user", "content": message})
|
|
|
|
| 221 |
|
| 222 |
response = model_output.choices[0].message.content
|
| 223 |
|
| 224 |
+
# Append the user's input and assistant's response to history
|
| 225 |
+
history.append((message, response))
|
| 226 |
|
| 227 |
return history
|
| 228 |
|
|
|
|
| 230 |
def main_loop(message, history):
|
| 231 |
return run_action(message, history)
|
| 232 |
|
| 233 |
+
|
| 234 |
+
|
| 235 |
+
|
| 236 |
+
|
| 237 |
+
|
| 238 |
+
|
| 239 |
+
|
| 240 |
demo = gr.ChatInterface(
|
| 241 |
main_loop,
|
| 242 |
chatbot=gr.Chatbot(
|