File size: 3,171 Bytes
bda28c2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a61bbef
 
 
bda28c2
 
 
 
 
 
 
 
 
 
 
 
 
 
74f6ea1
 
 
1229aa8
bda28c2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74f6ea1
bda28c2
 
 
74f6ea1
 
 
 
 
 
bda28c2
 
 
 
74f6ea1
bda28c2
 
74f6ea1
bda28c2
 
 
 
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import os
import json
from openai import OpenAI

# Mock classes to match BrowserGym official sample structure
class BrowserGymAction:
    def __init__(self, action_str):
        self.action_str = action_str

def parse_model_action(text):
    # Dummmy parser for official sample
    return text.strip()

# Constants for official sample
SYSTEM_PROMPT = "You are a web browsing agent."
MODEL_NAME = os.getenv("MODEL_NAME", "step-fun-3.5-flash") # Use env var if available
TEMPERATURE = 0.0
MAX_TOKENS = 512
FALLBACK_ACTION = "stop"
MAX_STEPS = 10

def main():
    # Prefer injected API_KEY and API_BASE_URL
    api_key = os.getenv("API_KEY") or os.getenv("OPENAI_API_KEY", "EMPTY")
    base_url = os.getenv("API_BASE_URL") or "https://api.openai.com/v1"
    
    client = OpenAI(
        api_key=api_key, 
        base_url=base_url,
        default_headers={
            "HTTP-Referer": "https://huggingface.co/spaces/armaan020/AegisOpenEnv",
            "X-Title": "AegisOpenEnv Official Sample check"
        } if "openrouter" in base_url.lower() else None
    )
    
    print(f"Official Sample Inference Logic Initialized (Model: {MODEL_NAME})...")
    
    # --- START OF USER PROVIDED SNIPPET ---
    history = []
    task_name = "official_sample_task"
    print(f"[START] task={task_name}", flush=True)
    step_count = 0
    score = 0.5
    try:
        # Dummy loop to represent the user snippet's context
        for step in range(MAX_STEPS):
            # user_content would normally be defined here with AXTree/Accessibility logs
            user_content = [{"type": "text", "text": "Task: Navigate to example.com"}]
            
            messages = [
                {
                    "role": "system",
                    "content": [{"type": "text", "text": SYSTEM_PROMPT}],
                },
                {
                    "role": "user",
                    "content": user_content,
                },
            ]

            try:
                completion = client.chat.completions.create(
                    model=MODEL_NAME,
                    messages=messages,
                    temperature=TEMPERATURE,
                    max_tokens=MAX_TOKENS,
                    stream=False,
                )
                response_text = completion.choices[0].message.content or ""
            except Exception as exc: 
                failure_msg = f"Model request failed ({exc}). Using fallback action."
                print(failure_msg, flush=True)
                response_text = FALLBACK_ACTION

            action_str = parse_model_action(response_text)
            print(f"Step {step}: model suggested -> {action_str}", flush=True)

            step_count += 1
            reward = 0.5  # dummy reward
            score += reward
            print(f"[STEP] step={step_count} reward={reward}", flush=True)

            break # Break here for safety in dummy script

        else:
            print(f"Reached max steps ({MAX_STEPS}).", flush=True)

    finally:
        print(f"[END] task={task_name} score={score} steps={step_count}", flush=True)
    # --- END OF USER PROVIDED SNIPPET ---

if __name__ == "__main__":
    main()