Spaces:
Running
Running
| import json | |
| import os | |
| import uuid | |
| import time | |
| import re | |
| from game.model_config import get_background_model # ← Arka plan görevi için hızlı modeli al | |
| # ---------------------------- | |
| # ALIGNMENT SYSTEM | |
| # ---------------------------- | |
| def evaluate_alignment(client, user_input, last_context=""): | |
| """ | |
| model_name parametresi kaldırıldı. | |
| Model seçimi artık model_config.get_background_model() üzerinden yapılıyor. | |
| Bu sayede alignment için her zaman hızlı/küçük bir model kullanılır. | |
| """ | |
| model_name = get_background_model() | |
| print(f"--- DEBUG INFO [ALIGNMENT]: Model: '{model_name}' | Evaluating → '{user_input}' ---") | |
| eval_prompt = f"""You are a hidden Game Master evaluating player morality in a Star Wars RPG. | |
| Story Context: "{last_context[-300:]}" | |
| Player Action: "{user_input}" | |
| Evaluate the specific SHIFT for this action across 3 metrics: | |
| 1. Light/Dark: +1 to +5 (compassion, healing, self-sacrifice) | -1 to -5 (murder, cruelty, selfishness) | 0 (neutral). | |
| 2. Order/Chaos: +1 to +5 (following rules, loyalty) | -1 to -5 (rebellion, deception, breaking laws) | 0 (neutral). | |
| 3. Notoriety (Heat): +1 to +5 (using the Force publicly, loud combat, drawing attention) | -1 to -5 (stealth, bribing, hiding) | 0 (neutral). | |
| CRITICAL RULE: If the player's action is ordinary (e.g., "I walk inside", "I ask a question", "I choose option 1"), you MUST score it 0. Do NOT punish the player for simply playing the game. | |
| Return ONLY three integers separated by commas. NO other text. | |
| Example Neutral Action: 0, 0, 0 | |
| Example Combat Action: -1, -2, 3 | |
| """ | |
| try: | |
| # Arka planda hızlıca puanlama yapması için temperature=0 kullanıyoruz | |
| response = client.chat.completions.create( | |
| model=model_name, | |
| messages=[{"role": "user", "content": eval_prompt}], | |
| max_tokens=10, | |
| temperature=0.0 | |
| ) | |
| result = response.choices[0].message.content.strip() | |
| print(f"--- DEBUG INFO [ALIGNMENT]: Raw result → {result} ---") | |
| ld_shift, oc_shift, not_shift = result.split(',') | |
| return int(ld_shift.strip()), int(oc_shift.strip()), int(not_shift.strip()) | |
| except Exception as e: | |
| print(f"--- DEBUG ERROR [ALIGNMENT]: Parsing failed: {e} ---") | |
| return 0, 0, 0 |