Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -66,28 +66,31 @@ game_running = False # Flag to manage game status
|
|
66 |
|
67 |
# Function to process user input and actions
|
68 |
def run_action(message, history):
|
69 |
-
global game_state, game_running # Access
|
70 |
|
71 |
-
if
|
72 |
-
|
|
|
|
|
73 |
|
74 |
if message.lower() == "start game":
|
|
|
75 |
return game_state["start"]
|
76 |
|
77 |
-
if
|
78 |
-
|
79 |
-
return "Game restarted! " + game_state["start"]
|
80 |
|
81 |
if message.lower() == "exit":
|
82 |
game_running = False
|
83 |
return "The game has ended. Type 'restart the game' to play again."
|
84 |
|
|
|
85 |
system_prompt = """You are an AI Game master. Your job is to write what \
|
86 |
-
happens next in a player's adventure game
|
87 |
Instructions: \
|
88 |
- Write only 1-3 sentences. \
|
89 |
-
- Please use simple and clear language that is easy for children to understand.
|
90 |
-
- Always write in second person, e.g.,
|
91 |
- Write in present tense."""
|
92 |
|
93 |
world_info = f"""
|
@@ -96,7 +99,6 @@ def run_action(message, history):
|
|
96 |
Town: {game_state['town']}
|
97 |
Your Character: {game_state['character']}"""
|
98 |
|
99 |
-
# Build the context for the conversation
|
100 |
messages = [
|
101 |
{"role": "system", "content": system_prompt},
|
102 |
{"role": "user", "content": world_info},
|
@@ -107,10 +109,8 @@ def run_action(message, history):
|
|
107 |
messages.append({"role": "assistant", "content": action[0]})
|
108 |
messages.append({"role": "user", "content": action[1]})
|
109 |
|
110 |
-
# Add the user's current action
|
111 |
messages.append({"role": "user", "content": message})
|
112 |
|
113 |
-
# Get the model's response
|
114 |
model_output = client.chat.completions.create(
|
115 |
model="meta-llama/Llama-3-70b-chat-hf",
|
116 |
messages=messages,
|
|
|
66 |
|
67 |
# Function to process user input and actions
|
68 |
def run_action(message, history):
|
69 |
+
global game_state, game_running # Access global variables
|
70 |
|
71 |
+
if message.lower() == "restart the game":
|
72 |
+
game_state = initialize_game_state()
|
73 |
+
game_running = True # Set the game as running
|
74 |
+
return "Game restarted! " + game_state["start"]
|
75 |
|
76 |
if message.lower() == "start game":
|
77 |
+
game_running = True # Set the game as running
|
78 |
return game_state["start"]
|
79 |
|
80 |
+
if not game_running:
|
81 |
+
return "The game has ended. Type 'restart the game' to play again."
|
|
|
82 |
|
83 |
if message.lower() == "exit":
|
84 |
game_running = False
|
85 |
return "The game has ended. Type 'restart the game' to play again."
|
86 |
|
87 |
+
# The rest of the function remains the same
|
88 |
system_prompt = """You are an AI Game master. Your job is to write what \
|
89 |
+
happens next in a player's adventure game. \
|
90 |
Instructions: \
|
91 |
- Write only 1-3 sentences. \
|
92 |
+
- Please use simple and clear language that is easy for children to understand. \
|
93 |
+
- Always write in second person, e.g., 'You look north and see...' \
|
94 |
- Write in present tense."""
|
95 |
|
96 |
world_info = f"""
|
|
|
99 |
Town: {game_state['town']}
|
100 |
Your Character: {game_state['character']}"""
|
101 |
|
|
|
102 |
messages = [
|
103 |
{"role": "system", "content": system_prompt},
|
104 |
{"role": "user", "content": world_info},
|
|
|
109 |
messages.append({"role": "assistant", "content": action[0]})
|
110 |
messages.append({"role": "user", "content": action[1]})
|
111 |
|
|
|
112 |
messages.append({"role": "user", "content": message})
|
113 |
|
|
|
114 |
model_output = client.chat.completions.create(
|
115 |
model="meta-llama/Llama-3-70b-chat-hf",
|
116 |
messages=messages,
|