prashasti commited on
Commit
c6b6b10
·
1 Parent(s): 29ab1d0

Changes for openenv validations

Browse files
Files changed (5) hide show
  1. pyproject.toml +74 -0
  2. requirements.txt +3 -1
  3. server/__init__.py +1 -0
  4. server/app.py +115 -0
  5. uv.lock +0 -0
pyproject.toml ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [build-system]
2
+ requires = ["setuptools>=61.0", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "debugops"
7
+ version = "1.0.0"
8
+ description = "DebugOps - AI Incident Response Environment for OpenEnv"
9
+ readme = "README.md"
10
+ requires-python = ">=3.11"
11
+ license = {text = "MIT"}
12
+
13
+ authors = [
14
+ {name = "Prashasti Poojary", email = "your.email@example.com"}
15
+ ]
16
+
17
+ keywords = [
18
+ "reinforcement-learning",
19
+ "incident-response",
20
+ "sre",
21
+ "devops",
22
+ "openenv"
23
+ ]
24
+
25
+ classifiers = [
26
+ "Development Status :: 4 - Beta",
27
+ "Intended Audience :: Developers",
28
+ "Intended Audience :: Science/Research",
29
+ "License :: OSI Approved :: MIT License",
30
+ "Programming Language :: Python :: 3",
31
+ "Programming Language :: Python :: 3.11",
32
+ "Programming Language :: Python :: 3.12",
33
+ "Topic :: Scientific/Engineering :: Artificial Intelligence",
34
+ ]
35
+
36
+ dependencies = [
37
+ "fastapi>=0.110.0",
38
+ "uvicorn>=0.29.0",
39
+ "pydantic>=2.6.4",
40
+ "openai>=1.0.0",
41
+ "openenv-core>=0.2.0",
42
+ "pyyaml>=6.0",
43
+ ]
44
+
45
+ [project.optional-dependencies]
46
+ dev = [
47
+ "pytest>=7.0",
48
+ "black>=23.0",
49
+ "flake8>=6.0,<7.2.0",
50
+ "ruff>=0.1.0",
51
+ ]
52
+
53
+ [project.urls]
54
+ Homepage = "https://github.com/pr1397/AI-Incident-Response-Environment"
55
+ Repository = "https://github.com/pr1397/AI-Incident-Response-Environment"
56
+ Issues = "https://github.com/pr1397/AI-Incident-Response-Environment/issues"
57
+ "HuggingFace Space" = "https://huggingface.co/spaces/prashasti12/AI-debugging-agent"
58
+
59
+ [project.scripts]
60
+ server = "server.app:main"
61
+
62
+ [tool.setuptools]
63
+ packages = ["env", "tasks", "agent", "grader", "server"]
64
+
65
+ [tool.setuptools.package-data]
66
+ "*" = ["*.yaml", "*.yml"]
67
+
68
+ [tool.ruff]
69
+ line-length = 100
70
+ target-version = "py311"
71
+
72
+ [tool.black]
73
+ line-length = 100
74
+ target-version = ["py311", "py312"]
requirements.txt CHANGED
@@ -1,4 +1,6 @@
1
  fastapi==0.110.0
2
  uvicorn==0.29.0
3
  pydantic==2.6.4
4
- openai>=1.0.0
 
 
 
1
  fastapi==0.110.0
2
  uvicorn==0.29.0
3
  pydantic==2.6.4
4
+ openai>=1.0.0
5
+ openenv-core>=0.2.0
6
+ pyyaml>=6.0
server/__init__.py ADDED
@@ -0,0 +1 @@
 
 
1
+ from env.environment import DebugEnv
server/app.py ADDED
@@ -0,0 +1,115 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ HF Spaces server — DebugOps Environment (OpenEnv compatible)
3
+
4
+ Exposes:
5
+ POST /reset
6
+ POST /step
7
+ GET /state
8
+ """
9
+
10
+ from __future__ import annotations
11
+ from typing import Dict, Any, Optional
12
+
13
+ import os
14
+ import uvicorn
15
+ from fastapi import FastAPI, HTTPException
16
+ from pydantic import BaseModel
17
+
18
+ # Import your environments
19
+ from tasks.task_simple import create_env as create_simple
20
+ from tasks.task_multi_service import create_env as create_multi
21
+ from tasks.task_critical import create_env as create_critical
22
+
23
+
24
+ app = FastAPI(title="DebugOps AI Environment", version="1.0.0")
25
+
26
+ # Global env instance
27
+ _env = None
28
+
29
+ class ResetRequest(BaseModel):
30
+ task: str = "simple" # simple | multi_service | critical
31
+
32
+
33
+ class StepRequest(BaseModel):
34
+ action: str
35
+
36
+ def create_env(task: str):
37
+ if task == "simple":
38
+ return create_simple()
39
+ elif task == "multi_service":
40
+ return create_multi()
41
+ elif task == "critical":
42
+ return create_critical()
43
+ else:
44
+ raise ValueError(f"Invalid task: {task}")
45
+
46
+
47
+ def get_env():
48
+ global _env
49
+ if _env is None:
50
+ raise HTTPException(status_code=400, detail="Call /reset first")
51
+ return _env
52
+
53
+ @app.get("/")
54
+ def root():
55
+ return {
56
+ "name": "DebugOps AI Environment",
57
+ "description": "Production debugging RL environment (OpenEnv compatible)",
58
+ "endpoints": ["/reset", "/step", "/state", "/health"],
59
+ }
60
+
61
+
62
+ @app.get("/health")
63
+ def health():
64
+ return {"status": "ok"}
65
+
66
+
67
+ @app.post("/reset")
68
+ def reset(request: ResetRequest):
69
+ global _env
70
+ try:
71
+ _env = create_env(request.task)
72
+ obs = _env.reset()
73
+
74
+ return {
75
+ "observation": obs,
76
+ "done": False,
77
+ }
78
+
79
+ except Exception as e:
80
+ raise HTTPException(status_code=500, detail=str(e))
81
+
82
+
83
+ @app.post("/step")
84
+ def step(request: StepRequest):
85
+ env = get_env()
86
+
87
+ try:
88
+ obs, reward, done, info = env.step(request.action)
89
+
90
+ return {
91
+ "observation": obs,
92
+ "reward": float(round(reward, 3)),
93
+ "done": done,
94
+ "info": info,
95
+ }
96
+
97
+ except Exception as e:
98
+ raise HTTPException(status_code=400, detail=str(e))
99
+
100
+
101
+ @app.get("/state")
102
+ def state():
103
+ env = get_env()
104
+ try:
105
+ return env.state()
106
+ except Exception as e:
107
+ raise HTTPException(status_code=400, detail=str(e))
108
+
109
+ def main():
110
+ port = int(os.getenv("PORT", 7860))
111
+ uvicorn.run(app, host="0.0.0.0", port=port)
112
+
113
+
114
+ if __name__ == "__main__":
115
+ main()
uv.lock ADDED
The diff for this file is too large to render. See raw diff