-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
37 lines (29 loc) · 804 Bytes
/
main.py
File metadata and controls
37 lines (29 loc) · 804 Bytes
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
from fastapi import FastAPI
from env.env import CodeEnv
from env.models import Action
from agent.llm_agent import LLMAgent
app = FastAPI()
env = CodeEnv()
agent = LLMAgent()
@app.get("/task")
def get_task():
state = env.reset()
return {
"problem": state.problem,
"difficulty": state.difficulty
}
@app.post("/run")
def run_code():
state = env.current_task
best_reward = 0
best_code = ""
for _ in range(3):
code = agent.act(type("obj", (), {"problem": state["description"]}))
result = env.step(Action(code=code))
if result.reward > best_reward:
best_reward = result.reward
best_code = code
return {
"best_code": best_code,
"reward": best_reward
}