Spaces:
Sleeping
Sleeping
fix: Debug logs and auto-load for NL translator, movement & production bugs
Browse files- Add comprehensive debug logging for movement commands (unit target setting, movement progress)
- Add comprehensive debug logging for production commands (queue updates, progress tracking)
- Fix NL translator initialization: auto-load model on first use via get_nl_translator()
- Fix NL interface: retry connection every 3s until translator is available
- This should resolve: movement bug, production bug, translator unavailability, examples loading forever
- __pycache__/ai_analysis.cpython-312.pyc +0 -0
- app.py +12 -0
- nl_translator.py +8 -0
- server.log +17 -0
- static/nl_interface.js +9 -1
- todos.txt +3 -1
__pycache__/ai_analysis.cpython-312.pyc
CHANGED
|
Binary files a/__pycache__/ai_analysis.cpython-312.pyc and b/__pycache__/ai_analysis.cpython-312.pyc differ
|
|
|
app.py
CHANGED
|
@@ -755,8 +755,14 @@ class ConnectionManager:
|
|
| 755 |
production_speed *= LOW_POWER_PRODUCTION_FACTOR # 50% speed when low power
|
| 756 |
|
| 757 |
building.production_progress += production_speed
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 758 |
if building.production_progress >= 1.0:
|
| 759 |
# Complete production
|
|
|
|
| 760 |
unit_type = UnitType(building.production_queue.pop(0))
|
| 761 |
spawn_pos = Position(
|
| 762 |
building.position.x + TILE_SIZE * 2,
|
|
@@ -1223,7 +1229,10 @@ class ConnectionManager:
|
|
| 1223 |
player_id = command.get("player_id", 0)
|
| 1224 |
preferred_building_id = command.get("building_id") # optional: choose production building
|
| 1225 |
|
|
|
|
|
|
|
| 1226 |
if not unit_type_str:
|
|
|
|
| 1227 |
return
|
| 1228 |
|
| 1229 |
try:
|
|
@@ -1279,6 +1288,9 @@ class ConnectionManager:
|
|
| 1279 |
|
| 1280 |
# Add to production queue
|
| 1281 |
suitable_building.production_queue.append(unit_type_str)
|
|
|
|
|
|
|
|
|
|
| 1282 |
|
| 1283 |
# Translated notification
|
| 1284 |
unit_name = LOCALIZATION.translate(player_language, f"unit.{unit_type_str}")
|
|
|
|
| 755 |
production_speed *= LOW_POWER_PRODUCTION_FACTOR # 50% speed when low power
|
| 756 |
|
| 757 |
building.production_progress += production_speed
|
| 758 |
+
|
| 759 |
+
# Debug log every 2 seconds (40 ticks at 20Hz)
|
| 760 |
+
if self.game_state.tick % 40 == 0:
|
| 761 |
+
print(f" ๐ญ Building {building.id} ({building.type}) producing: {building.production_queue[0]} - progress: {building.production_progress:.2%}")
|
| 762 |
+
|
| 763 |
if building.production_progress >= 1.0:
|
| 764 |
# Complete production
|
| 765 |
+
print(f" โ
Production complete! Creating {building.production_queue[0]}")
|
| 766 |
unit_type = UnitType(building.production_queue.pop(0))
|
| 767 |
spawn_pos = Position(
|
| 768 |
building.position.x + TILE_SIZE * 2,
|
|
|
|
| 1229 |
player_id = command.get("player_id", 0)
|
| 1230 |
preferred_building_id = command.get("building_id") # optional: choose production building
|
| 1231 |
|
| 1232 |
+
print(f"๐ญ BUILD_UNIT command received: unit_type={unit_type_str}, player={player_id}, building={preferred_building_id}")
|
| 1233 |
+
|
| 1234 |
if not unit_type_str:
|
| 1235 |
+
print(" โ No unit_type provided")
|
| 1236 |
return
|
| 1237 |
|
| 1238 |
try:
|
|
|
|
| 1288 |
|
| 1289 |
# Add to production queue
|
| 1290 |
suitable_building.production_queue.append(unit_type_str)
|
| 1291 |
+
print(f" โ
Added {unit_type_str} to {suitable_building.type} queue (building {suitable_building.id})")
|
| 1292 |
+
print(f" Queue is now: {suitable_building.production_queue}")
|
| 1293 |
+
print(f" Credits: {self.game_state.players[player_id].credits}")
|
| 1294 |
|
| 1295 |
# Translated notification
|
| 1296 |
unit_name = LOCALIZATION.translate(player_language, f"unit.{unit_type_str}")
|
nl_translator.py
CHANGED
|
@@ -234,4 +234,12 @@ def get_nl_translator() -> NLCommandTranslator:
|
|
| 234 |
global _translator
|
| 235 |
if _translator is None:
|
| 236 |
_translator = NLCommandTranslator()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 237 |
return _translator
|
|
|
|
| 234 |
global _translator
|
| 235 |
if _translator is None:
|
| 236 |
_translator = NLCommandTranslator()
|
| 237 |
+
# Ensure model is loaded
|
| 238 |
+
if not _translator.model_loaded:
|
| 239 |
+
print("๐ Loading NL translator model...")
|
| 240 |
+
success, error = _translator.load_model()
|
| 241 |
+
if success:
|
| 242 |
+
print("โ
NL translator model loaded successfully")
|
| 243 |
+
else:
|
| 244 |
+
print(f"โ Failed to load NL translator model: {error}")
|
| 245 |
return _translator
|
server.log
CHANGED
|
@@ -50,3 +50,20 @@ INFO: 127.0.0.1:39464 - "POST /api/nl/translate HTTP/1.1" 200 OK
|
|
| 50 |
๐ค AI built power_plant at 3707,2584
|
| 51 |
llama_context: n_ctx_per_seq (4096) < n_ctx_train (32768) -- the full capacity of the model will not be utilized
|
| 52 |
INFO: 127.0.0.1:42208 - "POST /api/nl/translate HTTP/1.1" 200 OK
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
๐ค AI built power_plant at 3707,2584
|
| 51 |
llama_context: n_ctx_per_seq (4096) < n_ctx_train (32768) -- the full capacity of the model will not be utilized
|
| 52 |
INFO: 127.0.0.1:42208 - "POST /api/nl/translate HTTP/1.1" 200 OK
|
| 53 |
+
llama_context: n_ctx_per_seq (4096) < n_ctx_train (32768) -- the full capacity of the model will not be utilized
|
| 54 |
+
llama_context: n_ctx_per_seq (4096) < n_ctx_train (32768) -- the full capacity of the model will not be utilized
|
| 55 |
+
llama_context: n_ctx_per_seq (4096) < n_ctx_train (32768) -- the full capacity of the model will not be utilized
|
| 56 |
+
llama_context: n_ctx_per_seq (4096) < n_ctx_train (32768) -- the full capacity of the model will not be utilized
|
| 57 |
+
INFO: 127.0.0.1:47132 - "GET / HTTP/1.1" 200 OK
|
| 58 |
+
INFO: connection closed
|
| 59 |
+
INFO: 127.0.0.1:47132 - "GET /static/nl_interface.css HTTP/1.1" 304 Not Modified
|
| 60 |
+
INFO: 127.0.0.1:34332 - "GET /static/nl_interface.js HTTP/1.1" 304 Not Modified
|
| 61 |
+
INFO: 127.0.0.1:47132 - "GET /api/translations/en HTTP/1.1" 200 OK
|
| 62 |
+
INFO: 127.0.0.1:34346 - "WebSocket /ws" [accepted]
|
| 63 |
+
INFO: connection open
|
| 64 |
+
INFO: 127.0.0.1:47132 - "GET /api/nl/status HTTP/1.1" 200 OK
|
| 65 |
+
INFO: 127.0.0.1:47132 - "GET /api/nl/examples?language=en HTTP/1.1" 200 OK
|
| 66 |
+
llama_context: n_ctx_per_seq (4096) < n_ctx_train (32768) -- the full capacity of the model will not be utilized
|
| 67 |
+
llama_context: n_ctx_per_seq (4096) < n_ctx_train (32768) -- the full capacity of the model will not be utilized
|
| 68 |
+
llama_context: n_ctx_per_seq (4096) < n_ctx_train (32768) -- the full capacity of the model will not be utilized
|
| 69 |
+
INFO: connection closed
|
static/nl_interface.js
CHANGED
|
@@ -137,13 +137,21 @@ class NLInterface {
|
|
| 137 |
await this.loadExamples();
|
| 138 |
} else {
|
| 139 |
this.translatorReady = false;
|
| 140 |
-
|
|
|
|
| 141 |
this.disableInput();
|
|
|
|
|
|
|
|
|
|
|
|
|
| 142 |
}
|
| 143 |
} catch (error) {
|
| 144 |
console.error('[NL] Failed to check translator status:', error);
|
| 145 |
this.updateStatus('error', 'Failed to connect to translator');
|
| 146 |
this.disableInput();
|
|
|
|
|
|
|
|
|
|
| 147 |
}
|
| 148 |
}
|
| 149 |
|
|
|
|
| 137 |
await this.loadExamples();
|
| 138 |
} else {
|
| 139 |
this.translatorReady = false;
|
| 140 |
+
const errorMsg = data.last_error || 'Translator loading...';
|
| 141 |
+
this.updateStatus('loading', errorMsg);
|
| 142 |
this.disableInput();
|
| 143 |
+
|
| 144 |
+
// Retry after 3 seconds if not available
|
| 145 |
+
console.log('[NL] Translator not ready, will retry in 3s...');
|
| 146 |
+
setTimeout(() => this.checkTranslatorStatus(), 3000);
|
| 147 |
}
|
| 148 |
} catch (error) {
|
| 149 |
console.error('[NL] Failed to check translator status:', error);
|
| 150 |
this.updateStatus('error', 'Failed to connect to translator');
|
| 151 |
this.disableInput();
|
| 152 |
+
|
| 153 |
+
// Retry after 5 seconds on error
|
| 154 |
+
setTimeout(() => this.checkTranslatorStatus(), 5000);
|
| 155 |
}
|
| 156 |
}
|
| 157 |
|
todos.txt
CHANGED
|
@@ -45,4 +45,6 @@ Integration Suggestions:
|
|
| 45 |
|
| 46 |
Be careful, as the same LLM is also used to product AI analysis,
|
| 47 |
to describe war situation in NL from game stats. So, you have to
|
| 48 |
-
make both (NL interface and AI anlaysis) works with only one LLM.
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
Be careful, as the same LLM is also used to product AI analysis,
|
| 47 |
to describe war situation in NL from game stats. So, you have to
|
| 48 |
+
make both (NL interface and AI anlaysis) works with only one LLM.
|
| 49 |
+
|
| 50 |
+
remove control groups or disable it by default
|