# the main environment file from fastapi import FastAPI from pydantic import BaseModel from environment.api_triage_env import APITriageEnv # creating an app and environment app = FastAPI() env = APITriageEnv() # defining a request model for /step endpoint # for fastapi so that it can understand that we expecting a JSON with an action field that is a text dtype class ActionRequest(BaseModel): action: str @app.post("/reset") def reset(): """ Starting a new API debugging episode """ print("INFO : reset endpoint is called , new debugging session started ") state = env.reset() return { "step" : state.step, "max_steps": state.max_steps, "incident_summary": state.incident_summary, "logs": state.logs, "response_code":state.response_code, "fix_applied": state.fix_applied, "is_resolved" : state.is_resolved } @app.get("/state") def state(): """ HELPs to return the current observation of the episode. """ print("INFO : current state of the Episode as follows ") current = env.state() return { "step" : current.step, "max_steps": current.max_steps, "incident_summary": current.incident_summary, "logs": current.logs, "response_code": current.response_code, "fix_applied": current.fix_applied, "is_resolved" : current.is_resolved } @app.post("/step") def step(request: ActionRequest): """ the agent sends an action and our environment will preocess it and update the state , returns what happened. """ """ action = what the agent wants to do (text) observation = what the agent sees after doing it (object with 7 fields) """ action = request.action print(f"INFO : Action received: {action}") # calling env.step() from api_triage_env.py file to process the action observation , reward , done , info = env.step(action) # here returning the result return { "observation": { "step" : observation.step, "max_steps": observation.max_steps, "incident_summary": observation.incident_summary, "logs": observation.logs, "response_code": observation.response_code, "fix_applied": observation.fix_applied, "is_resolved" : observation.is_resolved }, "reward": reward, "done": done, "info": info, } def main(): import uvicorn uvicorn.run("app:app", host="0.0.0.0", port=7860) if __name__ == "__main__": main()