rairo commited on
Commit
bfda5a8
·
verified ·
1 Parent(s): 33704a2

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +31 -41
main.py CHANGED
@@ -437,10 +437,10 @@ def validate_odysseus_v6(t: dict) -> (bool, str):
437
  @app.route('/api/trial/generate', methods=['POST'])
438
  def generate_trial():
439
  """
440
- Odysseus v6: The AI as a Game Architect.
441
- Directly synthesizes physics, entities, and logic from the image context.
442
  """
443
- logger.info(">>> ODYSSEUS V6: AUTONOMOUS GENERATION")
444
  uid = verify_token(request.headers.get('Authorization'))
445
  if not uid: return jsonify({"error": "Unauthorized"}), 401
446
 
@@ -452,49 +452,49 @@ def generate_trial():
452
  if existing: return jsonify(existing), 200
453
 
454
  lock_ref = db_ref.child(f"epiphanies/{ep_id}/trialLocks/{layer_key}")
455
- if lock_ref.get(): return jsonify({"error": "Architecting Simulation..."}), 409
456
  lock_ref.set({"uid": uid, "at": datetime.utcnow().isoformat()})
457
 
458
  try:
459
  layer_data = db_ref.child(f"epiphanies/{ep_id}/layers/{layer_key}").get() or {}
460
  context = layer_data.get('text', '')
461
 
462
- # THE OPEN-ENDED PROMPT
463
  trial_prompt = f"""
464
- Act as a Master Game Designer and Scientific Architect.
465
- Subject: {subject}. Context: {context}.
466
-
467
- Task: Invent a unique, fun, 30-second 2D physics interaction that demonstrates the First Principles of this subject.
468
- DO NOT use a template. Use your reasoning to decide what the user should do (e.g., Assemble a structure, trigger a reaction, balance forces, or mutate a system).
469
 
 
 
 
 
 
 
 
 
 
 
 
 
470
  MANDATORY JSON SCHEMA:
471
  {{
472
- "engine": {{"name": "odysseus", "version": "v6"}},
473
- "scenario_name": "Unique Name of the Experiment",
474
- "mission_brief": "Feynman-style goal for the user.",
475
- "world_settings": {{ "gravity": [x, y], "background_vibe": "string" }},
476
  "entities": [
477
  {{
478
  "id": "e1",
479
  "label": "Part Name",
480
- "shape": "circle | rectangle | polygon",
481
- "physics": {{ "mass": float, "restitution": 0-1, "isStatic": bool, "isDraggable": bool }},
482
- "spawn_logic": {{ "count": int, "position": "random | center | grid" }},
483
- "visuals": {{ "color": "hex", "glow": bool, "icon": "string" }}
484
  }}
485
  ],
486
  "logic_rules": [
487
- {{ "trigger": "onCollision | onDrag | onTimed", "action": "scale | destroy | spawn | win_progress", "details": "string" }}
488
  ],
489
- "victory_logic": {{
490
- "condition": "Explain the math (e.g. 'Stability > 80' or 'All pathogens destroyed')",
491
- "target_metric": "string",
492
- "threshold": int
493
- }},
494
- "revelation": {{
495
- "on_win": "Profound Feynman 'Aha!' moment.",
496
- "on_fail": "Socratic hint about the system's nature."
497
- }}
498
  }}
499
  """
500
 
@@ -506,27 +506,17 @@ def generate_trial():
506
 
507
  trial_data = json.loads(_strip_json_fences(res.text))
508
 
509
- if not validate_odysseus_v6(trial_data):
510
- lock_ref.delete()
511
- return jsonify({"error": "Architect failed to compile logic"}), 422
512
-
513
  user_ref = db_ref.child(f'users/{uid}')
514
- credits = user_ref.get().get('credits', 0)
515
- if credits < 4:
516
- lock_ref.delete()
517
- return jsonify({"error": "Insufficient Sparks"}), 402
518
 
519
  trial_data["createdAt"] = datetime.utcnow().isoformat()
520
  db_ref.child(trial_path).set(trial_data)
521
- user_ref.update({'credits': credits - 4})
522
-
523
  lock_ref.delete()
524
- logger.info(f"Odysseus v6 Architected unique game for {subject}")
525
  return jsonify(trial_data), 201
526
-
527
  except Exception as e:
528
  lock_ref.delete()
529
- logger.error(f"v6 Architectural Error: {e}")
530
  return jsonify({"error": str(e)}), 500
531
 
532
  # -----------------------------------------------------------------------------
 
437
  @app.route('/api/trial/generate', methods=['POST'])
438
  def generate_trial():
439
  """
440
+ Odysseus v6.1: The Layer-Specific Architect.
441
+ Enforces unique gameplay for Genesis vs Core vs Edge vs Future.
442
  """
443
+ logger.info(">>> ODYSSEUS V6.1: LAYER-SPECIFIC GENERATION")
444
  uid = verify_token(request.headers.get('Authorization'))
445
  if not uid: return jsonify({"error": "Unauthorized"}), 401
446
 
 
452
  if existing: return jsonify(existing), 200
453
 
454
  lock_ref = db_ref.child(f"epiphanies/{ep_id}/trialLocks/{layer_key}")
455
+ if lock_ref.get(): return jsonify({"error": "Synthesizing Layer Logic..."}), 409
456
  lock_ref.set({"uid": uid, "at": datetime.utcnow().isoformat()})
457
 
458
  try:
459
  layer_data = db_ref.child(f"epiphanies/{ep_id}/layers/{layer_key}").get() or {}
460
  context = layer_data.get('text', '')
461
 
462
+ # THE LAYER-PERSONALITY PROMPT
463
  trial_prompt = f"""
464
+ Act as a Master Game Designer. Subject: {subject}. Layer: {layer_key}.
465
+ Context: {context}.
 
 
 
466
 
467
+ TASK: Invent a unique 2D physics experiment.
468
+ CRITICAL: The gameplay MUST match the layer's personality:
469
+ - If 'genesis': Focus on ASSEMBLY or ORIGIN.
470
+ - If 'scientific_core': Focus on BASIC PHYSICS (Gravity/Friction/Heat).
471
+ - If 'engineering_edge': Focus on STRESS, TOLERANCE, or SPEED.
472
+ - If 'cross_pollination': Focus on HYBRIDIZATION or UNUSUAL FORCES.
473
+
474
+ PHYSICS RULES:
475
+ 1. The system must NOT win automatically.
476
+ 2. Implement ENTROPY: If the user does nothing, the 'Stability' metric must decrease by 2% per second.
477
+ 3. The user MUST use their 'Tool' (draggable or clicker) to counteract this decay.
478
+
479
  MANDATORY JSON SCHEMA:
480
  {{
481
+ "engine": {{"name": "odysseus", "version": "v6.1"}},
482
+ "scenario_name": "Unique Title",
483
+ "mission_brief": "Active goal for the user.",
484
+ "world_settings": {{ "gravity": [x, y], "entropy_decay": 0.02 }},
485
  "entities": [
486
  {{
487
  "id": "e1",
488
  "label": "Part Name",
489
+ "physics": {{ "mass": float, "restitution": 0.7, "isDraggable": bool }},
490
+ "visuals": {{ "color": "hex", "glow": bool }}
 
 
491
  }}
492
  ],
493
  "logic_rules": [
494
+ {{ "trigger": "onHold | onCollision | onDrag", "action": "increase_stability | boost_score" }}
495
  ],
496
+ "victory_logic": {{ "target_metric": "Stability", "threshold": 100, "hold_ms": 2000 }},
497
+ "revelation": {{ "on_win": "Feynman Insight", "on_fail": "Socratic Hint" }}
 
 
 
 
 
 
 
498
  }}
499
  """
500
 
 
506
 
507
  trial_data = json.loads(_strip_json_fences(res.text))
508
 
509
+ # Persistence & Deduction (4 Sparks)
 
 
 
510
  user_ref = db_ref.child(f'users/{uid}')
511
+ user_ref.update({'credits': (user_ref.get().get('credits', 0) or 0) - 4})
 
 
 
512
 
513
  trial_data["createdAt"] = datetime.utcnow().isoformat()
514
  db_ref.child(trial_path).set(trial_data)
 
 
515
  lock_ref.delete()
516
+
517
  return jsonify(trial_data), 201
 
518
  except Exception as e:
519
  lock_ref.delete()
 
520
  return jsonify({"error": str(e)}), 500
521
 
522
  # -----------------------------------------------------------------------------