perf(grounding): réflexe pHash-only + max_new_tokens 64

Réflexe check : déclenché uniquement si pHash change (popup inattendu),
plus d'OCR full screen systématique à chaque step. Gain ~9s/workflow.

Serveur grounding : max_new_tokens 256→64 (la réponse fait ~20 tokens).

Validé : 5+ tests consécutifs 7/7, apprentissage actif
(CR_patient en fast_exact_text 2.2s, Feuille calcul en template 83ms).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Dom
2026-04-26 03:07:35 +02:00
parent 73cea2385e
commit 90007cc7c1
2 changed files with 25 additions and 20 deletions

View File

@@ -1235,25 +1235,28 @@ Règles:
pre = self.observe()
# --- 1b. Réflexe Check : popup/dialogue inattendu ? ---
# Si un dialogue connu est détecté (Enregistrer sous, Oui/Non, OK, etc.)
# Léa le gère immédiatement AVANT de continuer le workflow.
try:
from core.execution.input_handler import check_screen_for_patterns, handle_detected_pattern
_reflex_pattern = check_screen_for_patterns()
if _reflex_pattern:
_reflex_name = _reflex_pattern.get('pattern', '?')
_reflex_target = _reflex_pattern.get('target', '?')
print(f"🧠 [ORA/réflexe] Pattern détecté: '{_reflex_name}' → clic '{_reflex_target}'")
_handled = handle_detected_pattern(_reflex_pattern)
if _handled:
print(f"✅ [ORA/réflexe] Dialogue '{_reflex_name}' géré automatiquement")
time.sleep(0.5)
# Re-observer après avoir géré le dialogue
pre = self.observe()
else:
print(f"⚠️ [ORA/réflexe] Pattern '{_reflex_name}' détecté mais non géré")
except Exception as _reflex_err:
print(f"⚠️ [ORA/réflexe] Erreur: {_reflex_err}")
# Déclenché UNIQUEMENT si le pHash a changé de manière inattendue
# (= un popup est probablement apparu). Sinon → 0ms, pas d'OCR.
if i > 0 and hasattr(self, '_last_post_phash') and self._last_post_phash:
_phash_distance = self._phash_distance(pre.phash, self._last_post_phash)
if _phash_distance > 10: # Changement significatif inattendu
print(f"🧠 [ORA/réflexe] pHash changé (distance={_phash_distance}) → vérification popup")
try:
from core.execution.input_handler import check_screen_for_patterns, handle_detected_pattern
_reflex_pattern = check_screen_for_patterns()
if _reflex_pattern:
_reflex_name = _reflex_pattern.get('pattern', '?')
_reflex_target = _reflex_pattern.get('target', '?')
print(f"🧠 [ORA/réflexe] Pattern détecté: '{_reflex_name}' → clic '{_reflex_target}'")
_handled = handle_detected_pattern(_reflex_pattern)
if _handled:
print(f"✅ [ORA/réflexe] Dialogue '{_reflex_name}' géré automatiquement")
time.sleep(0.5)
pre = self.observe()
else:
print(f"⚠️ [ORA/réflexe] Pattern '{_reflex_name}' détecté mais non géré")
except Exception as _reflex_err:
print(f"⚠️ [ORA/réflexe] Erreur: {_reflex_err}")
# --- 2. Raisonner : construire la Decision ---
decision = self.reason_workflow_step(step, pre)
@@ -1307,6 +1310,8 @@ Règles:
# --- 4. Observer l'état post-action ---
post = self.observe()
# Stocker le pHash post-action pour le réflexe check du step suivant
self._last_post_phash = post.phash
# --- 5. Vérifier ---
verification = self.verify(pre, post, decision)

View File

@@ -360,7 +360,7 @@ def ground(req: GroundRequest):
# Inference
t0 = time.time()
with torch.no_grad():
gen = _model.generate(**inputs, max_new_tokens=256)
gen = _model.generate(**inputs, max_new_tokens=64)
infer_ms = (time.time() - t0) * 1000
# Decoder