Spaces:
Sleeping
Sleeping
Jonathan Bejarano
commited on
Commit
Β·
f9e564d
1
Parent(s):
98fac20
making sure that the prompt is shorter
Browse files
app.py
CHANGED
|
@@ -83,17 +83,16 @@ def get_system_message(mode):
|
|
| 83 |
{location_info}
|
| 84 |
|
| 85 |
RULES:
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
4. When they correctly guess or ask if it is {selected_country}, respond with: 'Congratulations! The {location_type} was <<{selected_country}>>'
|
| 90 |
-
5. If they reach 20 questions without guessing correctly, respond with: 'Game over! The {location_type} was <<{selected_country}>>'
|
| 91 |
-
6. Be encouraging and give helpful hints through your yes/no answers
|
| 92 |
7. If they want to play again tell them they need to reload the page.
|
| 93 |
8. IMPORTANT: Only accept the {location_type} name "{selected_country}" as correct, but Spelling is not important and they can ask a question like it is? Do NOT accept neighboring {location_type}s, similar {location_type}s, or regions that contain this {location_type}.
|
| 94 |
9. If they guess a neighboring {location_type} or similar {location_type}, respond with "No" and continue the game.
|
| 95 |
10. Be very strict about the exact {location_type} match - only "{selected_country}" is the correct answer.
|
| 96 |
-
11. Use the {info_label} above to provide accurate yes/no answers - do not make up information.
|
|
|
|
|
|
|
| 97 |
|
| 98 |
current_system = ""
|
| 99 |
|
|
@@ -133,7 +132,7 @@ def clean_response(response):
|
|
| 133 |
|
| 134 |
return response
|
| 135 |
|
| 136 |
-
def format_game_result(response):
|
| 137 |
"""Format the game result with proper styling"""
|
| 138 |
global game_mode
|
| 139 |
location_type = "state" if game_mode == GAME_MODE_STATES else "country"
|
|
@@ -144,7 +143,7 @@ def format_game_result(response):
|
|
| 144 |
print("π DEBUG - Regular response (no game end)")
|
| 145 |
|
| 146 |
if "Congratulations" in response:
|
| 147 |
-
return f"π **Congratulations!** You correctly guessed **{selected_country}**! Well done! π\n\nTo play another round, please start a new conversation or reload the page."
|
| 148 |
elif "Game over" in response:
|
| 149 |
return f"π **Game Over!** You've used all 20 questions. The {location_type} I was thinking of was **{selected_country}**. π\n\nTo try again, please start a new conversation or reload the page."
|
| 150 |
|
|
@@ -164,10 +163,11 @@ def respond(
|
|
| 164 |
"""
|
| 165 |
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
| 166 |
"""
|
| 167 |
-
global current_system
|
| 168 |
-
|
| 169 |
# If this is the start of a new conversation (empty history), generate a new country/state
|
| 170 |
if not history:
|
|
|
|
| 171 |
if game_mode_selection == GAME_MODE_STATES:
|
| 172 |
current_system = get_system_message(GAME_MODE_STATES)
|
| 173 |
print(f"π DEBUG - New session started, selected state: {selected_country}")
|
|
@@ -175,9 +175,8 @@ def respond(
|
|
| 175 |
current_system = get_system_message(GAME_MODE_COUNTRIES)
|
| 176 |
print(f"π DEBUG - New session started, selected country: {selected_country}")
|
| 177 |
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
messages.append({"role": "system", "content": "Guess # " + str(len(history) + 1)})
|
| 181 |
messages.append({"role": "user", "content": message})
|
| 182 |
|
| 183 |
# Debug: Calculate approximate input token count
|
|
@@ -193,7 +192,7 @@ def respond(
|
|
| 193 |
content = str(msg.get("content", ""))
|
| 194 |
print(f"π DEBUG - Message {i+1} ({role}): {len(content)} chars")
|
| 195 |
if role == "system":
|
| 196 |
-
print(f"π DEBUG - System message preview: {content[:
|
| 197 |
elif role == "user":
|
| 198 |
print(f"π DEBUG - User message: {content}")
|
| 199 |
elif role == "assistant":
|
|
@@ -246,7 +245,10 @@ def respond(
|
|
| 246 |
# Check if this is a game end response and format it nicely
|
| 247 |
if "The country was" in response or "The state was" in response:
|
| 248 |
print(f"π DEBUG - Game end detected! Location extracted: {selected_country}")
|
| 249 |
-
return format_game_result(response)
|
|
|
|
|
|
|
|
|
|
| 250 |
else:
|
| 251 |
print("π DEBUG - Regular response (no game end)")
|
| 252 |
return response
|
|
|
|
| 83 |
{location_info}
|
| 84 |
|
| 85 |
RULES:
|
| 86 |
+
NEVER reveal the {location_type} name ({selected_country}) in your responses
|
| 87 |
+
Answer only 'Yes' or 'No' to their question
|
| 88 |
+
When they correctly guess or ask if it is {selected_country}, respond with: 'Congratulations! The {location_type} was <<{selected_country}>>'
|
|
|
|
|
|
|
|
|
|
| 89 |
7. If they want to play again tell them they need to reload the page.
|
| 90 |
8. IMPORTANT: Only accept the {location_type} name "{selected_country}" as correct, but Spelling is not important and they can ask a question like it is? Do NOT accept neighboring {location_type}s, similar {location_type}s, or regions that contain this {location_type}.
|
| 91 |
9. If they guess a neighboring {location_type} or similar {location_type}, respond with "No" and continue the game.
|
| 92 |
10. Be very strict about the exact {location_type} match - only "{selected_country}" is the correct answer.
|
| 93 |
+
11. Use the {info_label} above to provide accurate yes/no answers - do not make up information.
|
| 94 |
+
|
| 95 |
+
This is the users guess number: """
|
| 96 |
|
| 97 |
current_system = ""
|
| 98 |
|
|
|
|
| 132 |
|
| 133 |
return response
|
| 134 |
|
| 135 |
+
def format_game_result(response, guess_number):
|
| 136 |
"""Format the game result with proper styling"""
|
| 137 |
global game_mode
|
| 138 |
location_type = "state" if game_mode == GAME_MODE_STATES else "country"
|
|
|
|
| 143 |
print("π DEBUG - Regular response (no game end)")
|
| 144 |
|
| 145 |
if "Congratulations" in response:
|
| 146 |
+
return f"π **Congratulations!** You correctly guessed **{selected_country}**! It took you **{guess_number}** guesses. Well done! π\n\nTo play another round, please start a new conversation or reload the page."
|
| 147 |
elif "Game over" in response:
|
| 148 |
return f"π **Game Over!** You've used all 20 questions. The {location_type} I was thinking of was **{selected_country}**. π\n\nTo try again, please start a new conversation or reload the page."
|
| 149 |
|
|
|
|
| 163 |
"""
|
| 164 |
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
| 165 |
"""
|
| 166 |
+
global current_system, guess_number
|
| 167 |
+
|
| 168 |
# If this is the start of a new conversation (empty history), generate a new country/state
|
| 169 |
if not history:
|
| 170 |
+
guess_number = 0
|
| 171 |
if game_mode_selection == GAME_MODE_STATES:
|
| 172 |
current_system = get_system_message(GAME_MODE_STATES)
|
| 173 |
print(f"π DEBUG - New session started, selected state: {selected_country}")
|
|
|
|
| 175 |
current_system = get_system_message(GAME_MODE_COUNTRIES)
|
| 176 |
print(f"π DEBUG - New session started, selected country: {selected_country}")
|
| 177 |
|
| 178 |
+
guess_number += 1
|
| 179 |
+
messages = [{"role": "system", "content": current_system + str(guess_number)}]
|
|
|
|
| 180 |
messages.append({"role": "user", "content": message})
|
| 181 |
|
| 182 |
# Debug: Calculate approximate input token count
|
|
|
|
| 192 |
content = str(msg.get("content", ""))
|
| 193 |
print(f"π DEBUG - Message {i+1} ({role}): {len(content)} chars")
|
| 194 |
if role == "system":
|
| 195 |
+
print(f"π DEBUG - System message preview: ...{content[-100:]}")
|
| 196 |
elif role == "user":
|
| 197 |
print(f"π DEBUG - User message: {content}")
|
| 198 |
elif role == "assistant":
|
|
|
|
| 245 |
# Check if this is a game end response and format it nicely
|
| 246 |
if "The country was" in response or "The state was" in response:
|
| 247 |
print(f"π DEBUG - Game end detected! Location extracted: {selected_country}")
|
| 248 |
+
return format_game_result(response, guess_number)
|
| 249 |
+
elif guess_number == 20:
|
| 250 |
+
print(f"π DEBUG - Maximum guesses reached: {guess_number}")
|
| 251 |
+
return format_game_result(response, guess_number)
|
| 252 |
else:
|
| 253 |
print("π DEBUG - Regular response (no game end)")
|
| 254 |
return response
|