Spaces:
Running
Running
Update main.py
Browse files
main.py
CHANGED
|
@@ -434,13 +434,18 @@ def validate_odysseus_v6(t: dict) -> (bool, str):
|
|
| 434 |
return True, "ok"
|
| 435 |
except: return False, "Blueprint Error"
|
| 436 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 437 |
@app.route('/api/trial/generate', methods=['POST'])
|
| 438 |
def generate_trial():
|
| 439 |
"""
|
| 440 |
-
Odysseus
|
| 441 |
-
|
|
|
|
| 442 |
"""
|
| 443 |
-
logger.info(">>> ODYSSEUS
|
| 444 |
uid = verify_token(request.headers.get('Authorization'))
|
| 445 |
if not uid: return jsonify({"error": "Unauthorized"}), 401
|
| 446 |
|
|
@@ -452,49 +457,53 @@ 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": "Synthesizing
|
| 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
|
| 465 |
-
Context: {context}
|
| 466 |
-
|
| 467 |
-
TASK:
|
| 468 |
-
|
| 469 |
-
|
| 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": "
|
| 482 |
-
"
|
| 483 |
-
"
|
| 484 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 485 |
"entities": [
|
| 486 |
{{
|
| 487 |
-
"
|
| 488 |
-
"
|
| 489 |
-
"physics": {{ "mass": float, "
|
| 490 |
-
"
|
| 491 |
}}
|
| 492 |
],
|
| 493 |
-
"
|
| 494 |
-
|
| 495 |
-
|
| 496 |
-
|
| 497 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 498 |
}}
|
| 499 |
"""
|
| 500 |
|
|
@@ -506,17 +515,24 @@ def generate_trial():
|
|
| 506 |
|
| 507 |
trial_data = json.loads(_strip_json_fences(res.text))
|
| 508 |
|
| 509 |
-
#
|
| 510 |
user_ref = db_ref.child(f'users/{uid}')
|
| 511 |
-
|
|
|
|
|
|
|
|
|
|
| 512 |
|
| 513 |
trial_data["createdAt"] = datetime.utcnow().isoformat()
|
| 514 |
db_ref.child(trial_path).set(trial_data)
|
| 515 |
-
|
| 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 |
# -----------------------------------------------------------------------------
|
|
|
|
| 434 |
return True, "ok"
|
| 435 |
except: return False, "Blueprint Error"
|
| 436 |
|
| 437 |
+
# -----------------------------------------------------------------------------
|
| 438 |
+
# ODYSSEUS ENGINE V9: THE SOCRATIC SIMULATOR (ESSENTIAL VERB ENGINE)
|
| 439 |
+
# -----------------------------------------------------------------------------
|
| 440 |
+
|
| 441 |
@app.route('/api/trial/generate', methods=['POST'])
|
| 442 |
def generate_trial():
|
| 443 |
"""
|
| 444 |
+
Odysseus v9: The Socratic Simulator.
|
| 445 |
+
Synthesizes the physical laws and interaction verbs specific to the object.
|
| 446 |
+
Cost: 1 Spark.
|
| 447 |
"""
|
| 448 |
+
logger.info(">>> ODYSSEUS V9: GENERATING SOCRATIC SIMULATOR")
|
| 449 |
uid = verify_token(request.headers.get('Authorization'))
|
| 450 |
if not uid: return jsonify({"error": "Unauthorized"}), 401
|
| 451 |
|
|
|
|
| 457 |
if existing: return jsonify(existing), 200
|
| 458 |
|
| 459 |
lock_ref = db_ref.child(f"epiphanies/{ep_id}/trialLocks/{layer_key}")
|
| 460 |
+
if lock_ref.get(): return jsonify({"error": "Synthesizing First Principles..."}), 409
|
| 461 |
lock_ref.set({"uid": uid, "at": datetime.utcnow().isoformat()})
|
| 462 |
|
| 463 |
try:
|
| 464 |
layer_data = db_ref.child(f"epiphanies/{ep_id}/layers/{layer_key}").get() or {}
|
| 465 |
context = layer_data.get('text', '')
|
| 466 |
|
|
|
|
| 467 |
trial_prompt = f"""
|
| 468 |
+
Act as Athena's Simulator Architect.
|
| 469 |
+
Subject: {subject}. Layer: {layer_key}. Context: {context}
|
| 470 |
+
|
| 471 |
+
TASK: Identify the "Essential Scientific Verb" for this object (e.g. Expand, Ionize, Dampen, Pivot).
|
| 472 |
+
Design a 30-second interaction where the user operates the system's core physics.
|
| 473 |
+
DO NOT use a puzzle/slider template. Invent the interaction logic from scratch.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 474 |
|
| 475 |
MANDATORY JSON SCHEMA:
|
| 476 |
{{
|
| 477 |
+
"engine": {{"name": "odysseus", "version": "v9"}},
|
| 478 |
+
"verb": "The core scientific action (e.g. COMPRESS)",
|
| 479 |
+
"mission": "Feynman-style objective for the Seeker.",
|
| 480 |
+
"physics_world": {{
|
| 481 |
+
"gravity": [x, y],
|
| 482 |
+
"viscosity": float,
|
| 483 |
+
"entropy_decay_rate": float
|
| 484 |
+
}},
|
| 485 |
+
"user_tool": {{
|
| 486 |
+
"type": "emitter | attractor | manipulator",
|
| 487 |
+
"label": "Custom tool name",
|
| 488 |
+
"effect_on_system": "string"
|
| 489 |
+
}},
|
| 490 |
"entities": [
|
| 491 |
{{
|
| 492 |
+
"label": "string",
|
| 493 |
+
"role": "agent | target | hazard",
|
| 494 |
+
"physics": {{ "mass": float, "charge": float, "bounciness": float }},
|
| 495 |
+
"behavior": "How this entity reacts to the User Tool"
|
| 496 |
}}
|
| 497 |
],
|
| 498 |
+
"win_state": {{
|
| 499 |
+
"metric": "string (e.g. 'Pressure_Stable')",
|
| 500 |
+
"target": 100,
|
| 501 |
+
"hold_seconds": 3
|
| 502 |
+
}},
|
| 503 |
+
"revelation": {{
|
| 504 |
+
"on_win": "Feynman truth about the verb.",
|
| 505 |
+
"on_fail": "Socratic hint about the physics."
|
| 506 |
+
}}
|
| 507 |
}}
|
| 508 |
"""
|
| 509 |
|
|
|
|
| 515 |
|
| 516 |
trial_data = json.loads(_strip_json_fences(res.text))
|
| 517 |
|
| 518 |
+
# 1-Spark Seeker Economy
|
| 519 |
user_ref = db_ref.child(f'users/{uid}')
|
| 520 |
+
credits = (user_ref.get() or {}).get('credits', 0)
|
| 521 |
+
if credits < 1:
|
| 522 |
+
lock_ref.delete()
|
| 523 |
+
return jsonify({"error": "Insufficient Sparks"}), 402
|
| 524 |
|
| 525 |
trial_data["createdAt"] = datetime.utcnow().isoformat()
|
| 526 |
db_ref.child(trial_path).set(trial_data)
|
| 527 |
+
user_ref.update({'credits': credits - 1})
|
| 528 |
|
| 529 |
+
lock_ref.delete()
|
| 530 |
+
logger.info(f"Odysseus v9: Simulator manifested for {subject} with verb: {trial_data.get('verb')}")
|
| 531 |
return jsonify(trial_data), 201
|
| 532 |
+
|
| 533 |
except Exception as e:
|
| 534 |
lock_ref.delete()
|
| 535 |
+
logger.error(f"v9 Architecture Failure: {e}")
|
| 536 |
return jsonify({"error": str(e)}), 500
|
| 537 |
|
| 538 |
# -----------------------------------------------------------------------------
|