File size: 6,370 Bytes
ffbce00
 
 
34a42a5
ffbce00
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2adb9a0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ffbce00
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
from typing import Dict, Optional

from fastapi import FastAPI
from fastapi.responses import HTMLResponse
from fastapi.middleware.cors import CORSMiddleware
from pydantic import BaseModel

from suspect_x_environment import SuspectXEnvironment

app = FastAPI(title="Suspect X — AI Interrogation Room", version="1.0.0")

app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],
    allow_methods=["*"],
    allow_headers=["*"],
)

env = SuspectXEnvironment()


# ------------------------------------------------------------------
# Request models
# ------------------------------------------------------------------

class ResetRequest(BaseModel):
    n_facts: int = 3
    seed: Optional[int] = None
    difficulty: Optional[str] = None


class StepRequest(BaseModel):
    session_id: str
    action_type: str        # "question" | "suspect_answer" | "submit_accusation"
    content: Optional[str] = None
    accusation_json: Optional[Dict[str, str]] = None


# ------------------------------------------------------------------
# Routes
# ------------------------------------------------------------------

@app.get("/", response_class=HTMLResponse)
def root():
    return """
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Suspect X Environment - API Server</title>
        <style>
            :root {
                --primary: #4f46e5;
                --primary-hover: #4338ca;
                --bg: #0f172a;
                --surface: #1e293b;
                --text: #f8fafc;
                --text-muted: #94a3b8;
                --border: #334155;
            }
            body {
                font-family: 'Inter', system-ui, -apple-system, sans-serif;
                background-color: var(--bg);
                color: var(--text);
                margin: 0;
                padding: 0;
                display: flex;
                flex-direction: column;
                align-items: center;
                justify-content: center;
                min-height: 100vh;
            }
            .container {
                background-color: var(--surface);
                border: 1px solid var(--border);
                border-radius: 12px;
                padding: 40px;
                max-width: 600px;
                width: 90%;
                box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.5), 0 8px 10px -6px rgba(0, 0, 0, 0.5);
                text-align: center;
            }
            h1 {
                margin-top: 0;
                font-size: 2rem;
                font-weight: 700;
                background: linear-gradient(to right, #818cf8, #c084fc);
                -webkit-background-clip: text;
                -webkit-text-fill-color: transparent;
            }
            p {
                color: var(--text-muted);
                line-height: 1.6;
                margin-bottom: 30px;
            }
            .endpoints {
                text-align: left;
                background: var(--bg);
                padding: 20px;
                border-radius: 8px;
                border: 1px solid var(--border);
            }
            .endpoints h2 {
                font-size: 1.2rem;
                margin-top: 0;
                margin-bottom: 15px;
                color: var(--text);
            }
            .endpoint {
                margin-bottom: 10px;
                display: flex;
                align-items: center;
                gap: 10px;
            }
            .method {
                background: var(--primary);
                color: white;
                padding: 4px 8px;
                border-radius: 4px;
                font-size: 0.8rem;
                font-weight: 600;
                text-transform: uppercase;
                min-width: 45px;
                text-align: center;
            }
            .method.get { background: #10b981; }
            .method.post { background: #3b82f6; }
            code {
                font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
                color: #e2e8f0;
            }
            .btn {
                display: inline-block;
                background-color: var(--primary);
                color: white;
                text-decoration: none;
                padding: 12px 24px;
                border-radius: 6px;
                font-weight: 600;
                margin-top: 30px;
                transition: background-color 0.2s;
            }
            .btn:hover {
                background-color: var(--primary-hover);
            }
            .badge {
                display: inline-block;
                background: rgba(79, 70, 229, 0.2);
                color: #818cf8;
                padding: 4px 12px;
                border-radius: 9999px;
                font-size: 0.875rem;
                font-weight: 500;
                margin-bottom: 20px;
                border: 1px solid rgba(79, 70, 229, 0.3);
            }
        </style>
    </head>
    <body>
        <div class="container">
            <div class="badge">OpenEnv Hackathon</div>
            <h1>Suspect X Environment</h1>
            <p>The high-fidelity adversarial interrogation environment is running successfully. This API serves as the backbone for the multi-agent RLHF training loop.</p>
            
            <div class="endpoints">
                <h2>API Endpoints</h2>
                <div class="endpoint">
                    <span class="method post">POST</span> <code>/reset</code>
                </div>
                <div class="endpoint">
                    <span class="method post">POST</span> <code>/step</code>
                </div>
                <div class="endpoint">
                    <span class="method get">GET</span> <code>/state</code>
                </div>
            </div>
            
            <a href="/docs" class="btn">View API Documentation</a>
        </div>
    </body>
    </html>
    """


@app.post("/reset")
def reset(req: ResetRequest = ResetRequest()):
    return env.reset(n_facts=req.n_facts, seed=req.seed, difficulty=req.difficulty)


@app.post("/step")
def step(req: StepRequest):
    action = req.model_dump()
    return env.step(action)


@app.get("/state")
def state():
    return env.state