Spaces:
Running
Running
Update main.py
Browse files
main.py
CHANGED
|
@@ -438,14 +438,18 @@ def validate_odysseus_v6(t: dict) -> (bool, str):
|
|
| 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
|
| 445 |
-
|
| 446 |
Cost: 1 Spark.
|
| 447 |
"""
|
| 448 |
-
logger.info(">>> ODYSSEUS
|
| 449 |
uid = verify_token(request.headers.get('Authorization'))
|
| 450 |
if not uid: return jsonify({"error": "Unauthorized"}), 401
|
| 451 |
|
|
@@ -457,7 +461,7 @@ def generate_trial():
|
|
| 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": "
|
| 461 |
lock_ref.set({"uid": uid, "at": datetime.utcnow().isoformat()})
|
| 462 |
|
| 463 |
try:
|
|
@@ -465,45 +469,27 @@ def generate_trial():
|
|
| 465 |
context = layer_data.get('text', '')
|
| 466 |
|
| 467 |
trial_prompt = f"""
|
| 468 |
-
|
| 469 |
Subject: {subject}. Layer: {layer_key}. Context: {context}
|
| 470 |
|
| 471 |
-
TASK:
|
| 472 |
-
|
| 473 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 474 |
|
| 475 |
-
|
| 476 |
{{
|
| 477 |
-
"engine": {{"name": "odysseus", "version": "
|
| 478 |
-
"
|
| 479 |
-
"
|
| 480 |
-
"
|
| 481 |
-
|
| 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,7 +501,6 @@ def generate_trial():
|
|
| 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:
|
|
@@ -527,12 +512,12 @@ def generate_trial():
|
|
| 527 |
user_ref.update({'credits': credits - 1})
|
| 528 |
|
| 529 |
lock_ref.delete()
|
| 530 |
-
logger.info(f"Odysseus
|
| 531 |
return jsonify(trial_data), 201
|
| 532 |
|
| 533 |
except Exception as e:
|
| 534 |
lock_ref.delete()
|
| 535 |
-
logger.error(f"
|
| 536 |
return jsonify({"error": str(e)}), 500
|
| 537 |
|
| 538 |
# -----------------------------------------------------------------------------
|
|
|
|
| 438 |
# ODYSSEUS ENGINE V9: THE SOCRATIC SIMULATOR (ESSENTIAL VERB ENGINE)
|
| 439 |
# -----------------------------------------------------------------------------
|
| 440 |
|
| 441 |
+
# -----------------------------------------------------------------------------
|
| 442 |
+
# ODYSSEUS ENGINE V10: THE SOCRATIC INSTRUMENT (DYNAMIC CODE GEN)
|
| 443 |
+
# -----------------------------------------------------------------------------
|
| 444 |
+
|
| 445 |
@app.route('/api/trial/generate', methods=['POST'])
|
| 446 |
def generate_trial():
|
| 447 |
"""
|
| 448 |
+
Odysseus v10: The Socratic Instrument.
|
| 449 |
+
Architects a bespoke, interactive React Component based on the 'Essential Verb'.
|
| 450 |
Cost: 1 Spark.
|
| 451 |
"""
|
| 452 |
+
logger.info(">>> ODYSSEUS V10: ARCHITECTING SOCRATIC INSTRUMENT")
|
| 453 |
uid = verify_token(request.headers.get('Authorization'))
|
| 454 |
if not uid: return jsonify({"error": "Unauthorized"}), 401
|
| 455 |
|
|
|
|
| 461 |
if existing: return jsonify(existing), 200
|
| 462 |
|
| 463 |
lock_ref = db_ref.child(f"epiphanies/{ep_id}/trialLocks/{layer_key}")
|
| 464 |
+
if lock_ref.get(): return jsonify({"error": "Forging Instrument..."}), 409
|
| 465 |
lock_ref.set({"uid": uid, "at": datetime.utcnow().isoformat()})
|
| 466 |
|
| 467 |
try:
|
|
|
|
| 469 |
context = layer_data.get('text', '')
|
| 470 |
|
| 471 |
trial_prompt = f"""
|
| 472 |
+
You are 'Athena's Master Instrumentalist'.
|
| 473 |
Subject: {subject}. Layer: {layer_key}. Context: {context}
|
| 474 |
|
| 475 |
+
TASK: Design a bespoke, interactive React component named 'Instrument'.
|
| 476 |
+
This is NOT a simulation to watch. It is a TACTILE EXPERIMENT.
|
| 477 |
+
|
| 478 |
+
RULES FOR THE CODE:
|
| 479 |
+
1. THE VERB: Identify the core action (e.g. 'Pivoting the Valve', 'Saturating the Membrane').
|
| 480 |
+
2. ENTROPY: The system must fail/decay if the user does nothing (e.g. pressure leaks, energy fades).
|
| 481 |
+
3. INTERACTION: The user MUST use their mouse/touch to directly manipulate the physics.
|
| 482 |
+
4. PHYSICS: Use Matter.js for 'Physical Weight' or direct SVG manipulation.
|
| 483 |
+
5. STYLE: Cosmic Academic. Dark #0B1120 background, Gold #D4AF37 strokes. High contrast.
|
| 484 |
+
6. WIN: When a 'Scientific Equilibrium' is held for 3 seconds, show a 'Revelation Confirmed' button.
|
| 485 |
|
| 486 |
+
JSON SCHEMA:
|
| 487 |
{{
|
| 488 |
+
"engine": {{"name": "odysseus", "version": "v10"}},
|
| 489 |
+
"instrument_name": "Name of the experiment",
|
| 490 |
+
"mission_brief": "Active Socratic command (e.g. 'Counteract the torque to find the lift threshold.')",
|
| 491 |
+
"component_code": "FULL_REACT_CODE_STRING",
|
| 492 |
+
"feynman_truth": "The profound law discovered through play."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 493 |
}}
|
| 494 |
"""
|
| 495 |
|
|
|
|
| 501 |
|
| 502 |
trial_data = json.loads(_strip_json_fences(res.text))
|
| 503 |
|
|
|
|
| 504 |
user_ref = db_ref.child(f'users/{uid}')
|
| 505 |
credits = (user_ref.get() or {}).get('credits', 0)
|
| 506 |
if credits < 1:
|
|
|
|
| 512 |
user_ref.update({'credits': credits - 1})
|
| 513 |
|
| 514 |
lock_ref.delete()
|
| 515 |
+
logger.info(f"Odysseus v10: Instrument forged for {subject}")
|
| 516 |
return jsonify(trial_data), 201
|
| 517 |
|
| 518 |
except Exception as e:
|
| 519 |
lock_ref.delete()
|
| 520 |
+
logger.error(f"v10 Forging Error: {e}")
|
| 521 |
return jsonify({"error": str(e)}), 500
|
| 522 |
|
| 523 |
# -----------------------------------------------------------------------------
|