File size: 2,080 Bytes
9bd725a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
"""Modality registry -- each task type maps to a verifier and a rubric hint.

This is how Handicate improves across ALL the modalities, not just text: every task
is tagged with a type, and the reward routes to that type's objective verifier (where
one exists) blended with the judge's rubric score.

- python / bash / 3d / svg  -> objective execution/parse verifier (strong RL signal)
- image_prompt / audio_prompt / video_spec -> judge-only (the model learns to write good
  generation specs; the actual pixels/audio/video come from the dedicated generators
  -- ImageForge, Michiro, etc. -- which Handicate orchestrates)
"""
from core import verifiers

VERIFIERS = {
    "python": verifiers.verify_python,
    "bash": verifiers.verify_bash,
    "3d": verifiers.verify_3d,
    "svg": verifiers.verify_svg,
    "image_prompt": None,
    "audio_prompt": None,
    "video_spec": None,
}

RUBRIC_HINTS = {
    "python": "Return runnable Python in a ```python block; handle edge cases.",
    "bash": "Return a correct POSIX bash command/script in a ```bash block.",
    "3d": "Return Python using trimesh/numpy that builds a variable `mesh` (a valid trimesh).",
    "svg": "Return a complete <svg>...</svg> with real shapes; must parse.",
    "image_prompt": "Return a vivid, specific text-to-image prompt (subject, style, lighting, detail).",
    "audio_prompt": "Return a precise music/audio generation prompt (genre, mood, instruments, bpm).",
    "video_spec": "Return a concrete shot-by-shot video spec (scenes, motion, duration).",
}

# blend weight: how much the objective verifier counts vs the judge's rubric score
VERIFIER_WEIGHT = 0.6


def verifier_for(task_type):
    return VERIFIERS.get(task_type)


def blended_reward(task_type, judge_score, response_text):
    """Objective verifier (if any) blended with the LLM judge's rubric score."""
    vfn = VERIFIERS.get(task_type)
    if vfn is None:
        return judge_score
    try:
        v = vfn(response_text)
    except Exception:
        v = 0.0
    return VERIFIER_WEIGHT * v + (1 - VERIFIER_WEIGHT) * judge_score