File size: 2,255 Bytes
ffd85e1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
"""
WhipStudio OpenEnv Client

This module provides an EnvClient wrapper for interacting with the WhipStudio
ML debugging environment via HTTP.
"""

from openenv import EnvClient

from models import MLDebugAction, MLDebugObservation


def create_client(base_url: str = "http://localhost:7860") -> EnvClient[MLDebugAction, MLDebugObservation]:
    """
    Create an EnvClient for the WhipStudio environment.
    
    Args:
        base_url: The base URL of the WhipStudio server.
        
    Returns:
        An EnvClient configured for MLDebugAction/MLDebugObservation.
        
    Example:
        >>> client = create_client("http://localhost:7860")
        >>> obs = client.reset(task_id="task1")
        >>> print(obs.buggy_code)
        >>> 
        >>> # Use tools to debug
        >>> obs = client.step(MLDebugAction(
        ...     action_type="execute_snippet",
        ...     code="print('hello')",
        ...     episode_id=obs.episode_id,
        ... ))
        >>> print(f"Turn {obs.turn}: {obs.stdout}")
        >>>
        >>> # Submit a fix
        >>> obs = client.step(MLDebugAction(
        ...     action_type="submit_fix",
        ...     fixed_code="...",
        ...     episode_id=obs.episode_id,
        ... ))
        >>> print(f"Reward: {obs.reward}")
    """
    return EnvClient[MLDebugAction, MLDebugObservation](
        base_url=base_url,
        action_cls=MLDebugAction,
        observation_cls=MLDebugObservation,
    )


# Convenience alias
Client = create_client


if __name__ == "__main__":
    # Quick test
    import sys
    
    url = sys.argv[1] if len(sys.argv) > 1 else "http://localhost:7860"
    print(f"Connecting to {url}...")
    
    client = create_client(url)
    
    # Test reset
    obs = client.reset(task_id="task1")
    print(f"✓ Reset successful - Episode: {obs.episode_id[:8]}...")
    print(f"  Task: {obs.task_id}")
    print(f"  Turn: {obs.turn}")
    
    # Test a tool call
    obs = client.step(MLDebugAction(
        action_type="execute_snippet",
        code="print('Hello from client!')",
        episode_id=obs.episode_id,
    ))
    print(f"✓ Step successful - Turn: {obs.turn}")
    print(f"  stdout: {obs.stdout.strip()}")
    
    print("\n✅ Client working correctly!")