Spaces:
Sleeping
Sleeping
AdityaProCoder commited on
Commit ·
78ab82d
1
Parent(s): af8c4cf
Add OpenEnv hackathon submission docs and structure guidance
Browse files- .env.example +10 -0
- .gitignore +23 -0
- Dockerfile +14 -8
- README.md +7 -0
- autonomous_returns_v0/.env.example +0 -3
- autonomous_returns_v0/README.md +5 -4
- autonomous_returns_v0/baseline.py +3 -38
- pyproject.toml +4 -5
- run_baseline.py +5 -7
- run_server.py +2 -2
- server/Dockerfile +1 -1
- server/__init__.py +1 -1
- server/app.py +57 -17
- server/gradio_builder.py +7 -9
- spaces/Dockerfile +1 -1
- spaces/README.md +6 -6
- tests/test_gradio_builder.py +4 -2
- tests/test_server_web_launch.py +1 -1
- uv.lock +0 -0
.env.example
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# OpenAI API key
|
| 2 |
+
OPENAI_API_KEY=
|
| 3 |
+
|
| 4 |
+
# Google Vertex AI
|
| 5 |
+
VERTEX_PROJECT_ID=
|
| 6 |
+
VERTEX_LOCATION=us-central1
|
| 7 |
+
|
| 8 |
+
# Optional model/runtime overrides
|
| 9 |
+
MODEL_NAME=gpt-4o-mini
|
| 10 |
+
API_BASE_URL=https://api.openai.com/v1
|
.gitignore
CHANGED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Environment files
|
| 2 |
+
.env
|
| 3 |
+
.env.*
|
| 4 |
+
!.env.example
|
| 5 |
+
|
| 6 |
+
# Virtual environments
|
| 7 |
+
.venv/
|
| 8 |
+
venv/
|
| 9 |
+
|
| 10 |
+
# Python cache/bytecode
|
| 11 |
+
__pycache__/
|
| 12 |
+
*.py[cod]
|
| 13 |
+
*$py.class
|
| 14 |
+
|
| 15 |
+
# Tool caches
|
| 16 |
+
.pytest_cache/
|
| 17 |
+
.mypy_cache/
|
| 18 |
+
.ruff_cache/
|
| 19 |
+
|
| 20 |
+
# Packaging/build artifacts
|
| 21 |
+
*.egg-info/
|
| 22 |
+
build/
|
| 23 |
+
dist/
|
Dockerfile
CHANGED
|
@@ -1,29 +1,35 @@
|
|
| 1 |
# OpenEnv/FastAPI runtime image for AutonomousReturns-v0
|
| 2 |
-
FROM python:3.
|
| 3 |
|
| 4 |
WORKDIR /app
|
| 5 |
|
| 6 |
# Runtime safety + cleaner logs
|
| 7 |
ENV PYTHONDONTWRITEBYTECODE=1 \
|
| 8 |
PYTHONUNBUFFERED=1 \
|
|
|
|
| 9 |
PIP_NO_CACHE_DIR=1 \
|
| 10 |
ENABLE_WEB_INTERFACE=false \
|
| 11 |
PORT=8000
|
| 12 |
|
| 13 |
# Minimal OS deps + healthcheck utility
|
| 14 |
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 15 |
-
curl \
|
| 16 |
&& rm -rf /var/lib/apt/lists/*
|
| 17 |
|
| 18 |
-
#
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
COPY autonomous_returns_v0 ./autonomous_returns_v0
|
| 21 |
COPY server ./server
|
| 22 |
COPY openenv.yaml ./openenv.yaml
|
|
|
|
| 23 |
|
| 24 |
-
# Install
|
| 25 |
-
RUN
|
| 26 |
-
pip install .
|
| 27 |
|
| 28 |
EXPOSE 8000
|
| 29 |
|
|
@@ -32,4 +38,4 @@ HEALTHCHECK --interval=30s --timeout=3s --start-period=10s --retries=3 \
|
|
| 32 |
CMD curl -fsS http://localhost:8000/health || exit 1
|
| 33 |
|
| 34 |
# Start OpenEnv-compatible FastAPI app
|
| 35 |
-
CMD ["uvicorn", "
|
|
|
|
| 1 |
# OpenEnv/FastAPI runtime image for AutonomousReturns-v0
|
| 2 |
+
FROM python:3.12-slim
|
| 3 |
|
| 4 |
WORKDIR /app
|
| 5 |
|
| 6 |
# Runtime safety + cleaner logs
|
| 7 |
ENV PYTHONDONTWRITEBYTECODE=1 \
|
| 8 |
PYTHONUNBUFFERED=1 \
|
| 9 |
+
PATH="/app/.venv/bin:${PATH}" \
|
| 10 |
PIP_NO_CACHE_DIR=1 \
|
| 11 |
ENABLE_WEB_INTERFACE=false \
|
| 12 |
PORT=8000
|
| 13 |
|
| 14 |
# Minimal OS deps + healthcheck utility
|
| 15 |
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 16 |
+
curl ca-certificates \
|
| 17 |
&& rm -rf /var/lib/apt/lists/*
|
| 18 |
|
| 19 |
+
# Install uv for lockfile-based environment sync
|
| 20 |
+
RUN pip install --upgrade pip setuptools wheel uv
|
| 21 |
+
|
| 22 |
+
# Copy metadata/lock first to maximize Docker layer caching
|
| 23 |
+
COPY pyproject.toml uv.lock README.md ./
|
| 24 |
+
|
| 25 |
+
# Copy package source
|
| 26 |
COPY autonomous_returns_v0 ./autonomous_returns_v0
|
| 27 |
COPY server ./server
|
| 28 |
COPY openenv.yaml ./openenv.yaml
|
| 29 |
+
COPY run_baseline.py run_server.py ./
|
| 30 |
|
| 31 |
+
# Install dependencies and project exactly from lockfile
|
| 32 |
+
RUN uv sync --frozen --no-dev
|
|
|
|
| 33 |
|
| 34 |
EXPOSE 8000
|
| 35 |
|
|
|
|
| 38 |
CMD curl -fsS http://localhost:8000/health || exit 1
|
| 39 |
|
| 40 |
# Start OpenEnv-compatible FastAPI app
|
| 41 |
+
CMD ["uvicorn", "server.app:app", "--host", "0.0.0.0", "--port", "8000"]
|
README.md
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# AutonomousReturns-v0
|
| 2 |
+
|
| 3 |
+
OpenEnv-compatible reverse-logistics environment for e-commerce returns triage.
|
| 4 |
+
|
| 5 |
+
- Package docs: `autonomous_returns_v0/README.md`
|
| 6 |
+
- Server entrypoint: `server.app:app`
|
| 7 |
+
- CLI scripts: `server`, `run-server`, `baseline`
|
autonomous_returns_v0/.env.example
CHANGED
|
@@ -1,9 +1,6 @@
|
|
| 1 |
# OpenAI API key (get from https://platform.openai.com/api-keys)
|
| 2 |
OPENAI_API_KEY=your_openai_key_here
|
| 3 |
|
| 4 |
-
# Anthropic API key (get from https://console.anthropic.com/settings/keys)
|
| 5 |
-
ANTHROPIC_API_KEY=your_anthropic_key_here
|
| 6 |
-
|
| 7 |
# Google Vertex AI (use `gcloud auth application-default login` for auth)
|
| 8 |
VERTEX_PROJECT_ID=your-gcp-project-id
|
| 9 |
VERTEX_LOCATION=us-central1
|
|
|
|
| 1 |
# OpenAI API key (get from https://platform.openai.com/api-keys)
|
| 2 |
OPENAI_API_KEY=your_openai_key_here
|
| 3 |
|
|
|
|
|
|
|
|
|
|
| 4 |
# Google Vertex AI (use `gcloud auth application-default login` for auth)
|
| 5 |
VERTEX_PROJECT_ID=your-gcp-project-id
|
| 6 |
VERTEX_LOCATION=us-central1
|
autonomous_returns_v0/README.md
CHANGED
|
@@ -137,7 +137,8 @@ Optional:
|
|
| 137 |
|
| 138 |
```bash
|
| 139 |
pip install ".[openai]"
|
| 140 |
-
pip install ".[
|
|
|
|
| 141 |
pip install ".[all]"
|
| 142 |
```
|
| 143 |
|
|
@@ -164,7 +165,7 @@ uv run run-server
|
|
| 164 |
Runtime contract validation:
|
| 165 |
|
| 166 |
```bash
|
| 167 |
-
uvicorn
|
| 168 |
openenv validate --url http://127.0.0.1:8000
|
| 169 |
```
|
| 170 |
|
|
@@ -220,10 +221,10 @@ Deterministic local baseline (this branch, current implementation):
|
|
| 220 |
|
| 221 |
## Optional LLM Baseline
|
| 222 |
|
| 223 |
-
OpenAI/
|
| 224 |
|
| 225 |
- `OPENAI_API_KEY`
|
| 226 |
-
- `
|
| 227 |
|
| 228 |
Example:
|
| 229 |
|
|
|
|
| 137 |
|
| 138 |
```bash
|
| 139 |
pip install ".[openai]"
|
| 140 |
+
pip install ".[vertex]"
|
| 141 |
+
pip install ".[web]"
|
| 142 |
pip install ".[all]"
|
| 143 |
```
|
| 144 |
|
|
|
|
| 165 |
Runtime contract validation:
|
| 166 |
|
| 167 |
```bash
|
| 168 |
+
uvicorn server.app:app --host 127.0.0.1 --port 8000
|
| 169 |
openenv validate --url http://127.0.0.1:8000
|
| 170 |
```
|
| 171 |
|
|
|
|
| 221 |
|
| 222 |
## Optional LLM Baseline
|
| 223 |
|
| 224 |
+
OpenAI/Google baseline runner is available but non-deterministic over time:
|
| 225 |
|
| 226 |
- `OPENAI_API_KEY`
|
| 227 |
+
- `VERTEX_PROJECT_ID`
|
| 228 |
|
| 229 |
Example:
|
| 230 |
|
autonomous_returns_v0/baseline.py
CHANGED
|
@@ -5,7 +5,7 @@ Features:
|
|
| 5 |
- OpenEnv-compatible typed actions (`ReturnsAction`)
|
| 6 |
- Robust handling of delayed-reward tail steps (`WAIT`)
|
| 7 |
- Reproducible benchmark runner across easy/medium/hard tasks
|
| 8 |
-
- OpenAI/
|
| 9 |
"""
|
| 10 |
|
| 11 |
from __future__ import annotations
|
|
@@ -97,21 +97,6 @@ class BaselineAgent:
|
|
| 97 |
if not self.model:
|
| 98 |
self.model = os.environ.get("MODEL_NAME", "gpt-4o-mini")
|
| 99 |
|
| 100 |
-
elif self.provider == "anthropic":
|
| 101 |
-
try:
|
| 102 |
-
anthropic_mod = import_module("anthropic")
|
| 103 |
-
Anthropic = getattr(anthropic_mod, "Anthropic")
|
| 104 |
-
except Exception as exc:
|
| 105 |
-
raise ImportError(
|
| 106 |
-
"anthropic package required. Install with: pip install anthropic"
|
| 107 |
-
) from exc
|
| 108 |
-
|
| 109 |
-
api_key = os.environ.get("ANTHROPIC_API_KEY")
|
| 110 |
-
if not api_key:
|
| 111 |
-
raise ValueError("ANTHROPIC_API_KEY environment variable not set")
|
| 112 |
-
self.client = Anthropic(api_key=api_key)
|
| 113 |
-
if not self.model:
|
| 114 |
-
self.model = "claude-3-5-haiku-20241022"
|
| 115 |
elif self.provider == "google":
|
| 116 |
project_id = os.environ.get("VERTEX_PROJECT_ID")
|
| 117 |
if not project_id:
|
|
@@ -121,7 +106,7 @@ class BaselineAgent:
|
|
| 121 |
if not self.model:
|
| 122 |
self.model = "gemini-1.5-pro"
|
| 123 |
else:
|
| 124 |
-
raise ValueError("Unknown provider. Use 'openai'
|
| 125 |
|
| 126 |
def _call_llm(self, prompt: str) -> str:
|
| 127 |
system_msg = LLM_SYSTEM_PROMPT
|
|
@@ -139,15 +124,6 @@ class BaselineAgent:
|
|
| 139 |
text = response.choices[0].message.content or ""
|
| 140 |
return text.strip()
|
| 141 |
|
| 142 |
-
if self.provider == "anthropic":
|
| 143 |
-
response = self.client.messages.create(
|
| 144 |
-
model=self.model,
|
| 145 |
-
max_tokens=self.config.max_tokens,
|
| 146 |
-
system=system_msg,
|
| 147 |
-
messages=[{"role": "user", "content": prompt}],
|
| 148 |
-
)
|
| 149 |
-
return response.content[0].text.strip()
|
| 150 |
-
|
| 151 |
init(project=self._vertex_project, location=self._vertex_location)
|
| 152 |
model = GenerativeModel(
|
| 153 |
self.model,
|
|
@@ -318,17 +294,6 @@ def run_openai_baseline(
|
|
| 318 |
) -> dict:
|
| 319 |
agent = BaselineAgent(BaselineRunConfig(provider="openai", model=model))
|
| 320 |
return agent.run_benchmark(seeds=seeds, verbose=verbose)
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
def run_anthropic_baseline(
|
| 324 |
-
model: str = "claude-3-5-haiku-20241022",
|
| 325 |
-
seeds: Iterable[int] = (42,),
|
| 326 |
-
verbose: bool = False,
|
| 327 |
-
) -> dict:
|
| 328 |
-
agent = BaselineAgent(BaselineRunConfig(provider="anthropic", model=model))
|
| 329 |
-
return agent.run_benchmark(seeds=seeds, verbose=verbose)
|
| 330 |
-
|
| 331 |
-
|
| 332 |
if __name__ == "__main__":
|
| 333 |
result = run_openai_baseline(verbose=True)
|
| 334 |
-
print(result)
|
|
|
|
| 5 |
- OpenEnv-compatible typed actions (`ReturnsAction`)
|
| 6 |
- Robust handling of delayed-reward tail steps (`WAIT`)
|
| 7 |
- Reproducible benchmark runner across easy/medium/hard tasks
|
| 8 |
+
- OpenAI/Vertex AI model support with env-var credentials
|
| 9 |
"""
|
| 10 |
|
| 11 |
from __future__ import annotations
|
|
|
|
| 97 |
if not self.model:
|
| 98 |
self.model = os.environ.get("MODEL_NAME", "gpt-4o-mini")
|
| 99 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
elif self.provider == "google":
|
| 101 |
project_id = os.environ.get("VERTEX_PROJECT_ID")
|
| 102 |
if not project_id:
|
|
|
|
| 106 |
if not self.model:
|
| 107 |
self.model = "gemini-1.5-pro"
|
| 108 |
else:
|
| 109 |
+
raise ValueError("Unknown provider. Use 'openai' or 'google'.")
|
| 110 |
|
| 111 |
def _call_llm(self, prompt: str) -> str:
|
| 112 |
system_msg = LLM_SYSTEM_PROMPT
|
|
|
|
| 124 |
text = response.choices[0].message.content or ""
|
| 125 |
return text.strip()
|
| 126 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
init(project=self._vertex_project, location=self._vertex_location)
|
| 128 |
model = GenerativeModel(
|
| 129 |
self.model,
|
|
|
|
| 294 |
) -> dict:
|
| 295 |
agent = BaselineAgent(BaselineRunConfig(provider="openai", model=model))
|
| 296 |
return agent.run_benchmark(seeds=seeds, verbose=verbose)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 297 |
if __name__ == "__main__":
|
| 298 |
result = run_openai_baseline(verbose=True)
|
| 299 |
+
print(result)
|
pyproject.toml
CHANGED
|
@@ -11,7 +11,6 @@ requires-python = ">=3.10"
|
|
| 11 |
dependencies = [
|
| 12 |
"openenv-core[core]>=0.2.2",
|
| 13 |
"fastapi>=0.115.0",
|
| 14 |
-
"gradio>=6.0.0",
|
| 15 |
"pydantic>=2.0.0",
|
| 16 |
"uvicorn>=0.24.0",
|
| 17 |
"numpy>=1.20",
|
|
@@ -22,20 +21,20 @@ dependencies = [
|
|
| 22 |
|
| 23 |
[project.optional-dependencies]
|
| 24 |
openai = ["openai>=1.0"]
|
| 25 |
-
anthropic = ["anthropic>=0.18"]
|
| 26 |
vertex = ["google-cloud-aiplatform>=1.145.0"]
|
| 27 |
-
|
|
|
|
| 28 |
dev = [
|
| 29 |
"pytest>=8.0.0",
|
| 30 |
"pytest-cov>=4.0.0",
|
| 31 |
]
|
| 32 |
|
| 33 |
[project.scripts]
|
| 34 |
-
server = "
|
| 35 |
run-server = "run_server:main"
|
| 36 |
baseline = "run_baseline:main"
|
| 37 |
|
| 38 |
[tool.setuptools]
|
| 39 |
include-package-data = true
|
| 40 |
-
packages = ["autonomous_returns_v0", "
|
| 41 |
py-modules = ["run_baseline", "run_server"]
|
|
|
|
| 11 |
dependencies = [
|
| 12 |
"openenv-core[core]>=0.2.2",
|
| 13 |
"fastapi>=0.115.0",
|
|
|
|
| 14 |
"pydantic>=2.0.0",
|
| 15 |
"uvicorn>=0.24.0",
|
| 16 |
"numpy>=1.20",
|
|
|
|
| 21 |
|
| 22 |
[project.optional-dependencies]
|
| 23 |
openai = ["openai>=1.0"]
|
|
|
|
| 24 |
vertex = ["google-cloud-aiplatform>=1.145.0"]
|
| 25 |
+
web = ["gradio>=6.0.0"]
|
| 26 |
+
all = ["openai>=1.0", "google-cloud-aiplatform>=1.145.0", "gradio>=6.0.0"]
|
| 27 |
dev = [
|
| 28 |
"pytest>=8.0.0",
|
| 29 |
"pytest-cov>=4.0.0",
|
| 30 |
]
|
| 31 |
|
| 32 |
[project.scripts]
|
| 33 |
+
server = "server.app:main"
|
| 34 |
run-server = "run_server:main"
|
| 35 |
baseline = "run_baseline:main"
|
| 36 |
|
| 37 |
[tool.setuptools]
|
| 38 |
include-package-data = true
|
| 39 |
+
packages = ["autonomous_returns_v0", "server"]
|
| 40 |
py-modules = ["run_baseline", "run_server"]
|
run_baseline.py
CHANGED
|
@@ -28,15 +28,13 @@ def _parse_int_csv(value: str) -> list[int]:
|
|
| 28 |
|
| 29 |
|
| 30 |
def _auto_detect_provider() -> str:
|
| 31 |
-
"""Auto-detect LLM provider based on available API keys. Priority: openai >
|
| 32 |
if os.getenv("OPENAI_API_KEY"):
|
| 33 |
return "openai"
|
| 34 |
-
if os.getenv("ANTHROPIC_API_KEY"):
|
| 35 |
-
return "anthropic"
|
| 36 |
if os.getenv("GEMINI_API_KEY"):
|
| 37 |
return "google"
|
| 38 |
raise ValueError(
|
| 39 |
-
"No LLM API key found. Set OPENAI_API_KEY
|
| 40 |
)
|
| 41 |
|
| 42 |
|
|
@@ -62,14 +60,14 @@ def build_parser() -> argparse.ArgumentParser:
|
|
| 62 |
parser = argparse.ArgumentParser(
|
| 63 |
description=(
|
| 64 |
"AutonomousReturns-v0 baseline CLI. "
|
| 65 |
-
"Supports deterministic local baseline and optional LLM baseline."
|
| 66 |
)
|
| 67 |
)
|
| 68 |
parser.add_argument(
|
| 69 |
"--mode",
|
| 70 |
choices=("local", "llm"),
|
| 71 |
default="local",
|
| 72 |
-
help="Execution mode: local (deterministic) or llm (auto/OpenAI/
|
| 73 |
)
|
| 74 |
parser.add_argument(
|
| 75 |
"--tasks",
|
|
@@ -83,7 +81,7 @@ def build_parser() -> argparse.ArgumentParser:
|
|
| 83 |
)
|
| 84 |
parser.add_argument(
|
| 85 |
"--provider",
|
| 86 |
-
choices=("auto", "openai", "
|
| 87 |
default="auto",
|
| 88 |
help="LLM provider (used only in --mode llm). Use 'auto' to detect from API keys.",
|
| 89 |
)
|
|
|
|
| 28 |
|
| 29 |
|
| 30 |
def _auto_detect_provider() -> str:
|
| 31 |
+
"""Auto-detect LLM provider based on available API keys. Priority: openai > google."""
|
| 32 |
if os.getenv("OPENAI_API_KEY"):
|
| 33 |
return "openai"
|
|
|
|
|
|
|
| 34 |
if os.getenv("GEMINI_API_KEY"):
|
| 35 |
return "google"
|
| 36 |
raise ValueError(
|
| 37 |
+
"No LLM API key found. Set OPENAI_API_KEY or GEMINI_API_KEY in .env"
|
| 38 |
)
|
| 39 |
|
| 40 |
|
|
|
|
| 60 |
parser = argparse.ArgumentParser(
|
| 61 |
description=(
|
| 62 |
"AutonomousReturns-v0 baseline CLI. "
|
| 63 |
+
"Supports deterministic local baseline and optional LLM baseline (OpenAI/Google)."
|
| 64 |
)
|
| 65 |
)
|
| 66 |
parser.add_argument(
|
| 67 |
"--mode",
|
| 68 |
choices=("local", "llm"),
|
| 69 |
default="local",
|
| 70 |
+
help="Execution mode: local (deterministic) or llm (auto/OpenAI/Google).",
|
| 71 |
)
|
| 72 |
parser.add_argument(
|
| 73 |
"--tasks",
|
|
|
|
| 81 |
)
|
| 82 |
parser.add_argument(
|
| 83 |
"--provider",
|
| 84 |
+
choices=("auto", "openai", "google"),
|
| 85 |
default="auto",
|
| 86 |
help="LLM provider (used only in --mode llm). Use 'auto' to detect from API keys.",
|
| 87 |
)
|
run_server.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
"""Single-command launcher for local OpenEnv +
|
| 2 |
|
| 3 |
from __future__ import annotations
|
| 4 |
|
|
@@ -15,7 +15,7 @@ def main() -> None:
|
|
| 15 |
os.environ.setdefault("ENV_README_PATH", os.path.abspath(os.path.join(os.path.dirname(__file__), "README.md")))
|
| 16 |
port = int(os.getenv("PORT", "8000"))
|
| 17 |
|
| 18 |
-
app_module = import_module("
|
| 19 |
app = getattr(app_module, "build_app")()
|
| 20 |
|
| 21 |
print(f"Web UI: http://localhost:{port}/web/")
|
|
|
|
| 1 |
+
"""Single-command launcher for local OpenEnv API + optional web UI."""
|
| 2 |
|
| 3 |
from __future__ import annotations
|
| 4 |
|
|
|
|
| 15 |
os.environ.setdefault("ENV_README_PATH", os.path.abspath(os.path.join(os.path.dirname(__file__), "README.md")))
|
| 16 |
port = int(os.getenv("PORT", "8000"))
|
| 17 |
|
| 18 |
+
app_module = import_module("server.app")
|
| 19 |
app = getattr(app_module, "build_app")()
|
| 20 |
|
| 21 |
print(f"Web UI: http://localhost:{port}/web/")
|
server/Dockerfile
CHANGED
|
@@ -32,4 +32,4 @@ HEALTHCHECK --interval=30s --timeout=3s --start-period=10s --retries=3 \
|
|
| 32 |
CMD curl -fsS http://localhost:8000/health || exit 1
|
| 33 |
|
| 34 |
# OpenEnv-compatible FastAPI server
|
| 35 |
-
CMD ["uvicorn", "
|
|
|
|
| 32 |
CMD curl -fsS http://localhost:8000/health || exit 1
|
| 33 |
|
| 34 |
# OpenEnv-compatible FastAPI server
|
| 35 |
+
CMD ["uvicorn", "server.app:app", "--host", "0.0.0.0", "--port", "8000"]
|
server/__init__.py
CHANGED
|
@@ -5,5 +5,5 @@ This package enables import paths such as:
|
|
| 5 |
- `server.app:app`
|
| 6 |
|
| 7 |
The actual FastAPI app is provided in `server/app.py` (root-level wrapper)
|
| 8 |
-
and
|
| 9 |
"""
|
|
|
|
| 5 |
- `server.app:app`
|
| 6 |
|
| 7 |
The actual FastAPI app is provided in `server/app.py` (root-level wrapper)
|
| 8 |
+
and builds the runtime app directly from `autonomous_returns_v0`.
|
| 9 |
"""
|
server/app.py
CHANGED
|
@@ -1,35 +1,75 @@
|
|
| 1 |
-
"""
|
| 2 |
-
Root server app wrapper for AutonomousReturns-v0.
|
| 3 |
|
| 4 |
-
|
| 5 |
-
at repository root. It delegates to the package implementation at
|
| 6 |
-
`autonomous_returns_v0.server.app`.
|
| 7 |
-
"""
|
| 8 |
|
| 9 |
import os
|
| 10 |
-
from importlib import import_module
|
|
|
|
| 11 |
|
|
|
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
return build_app()
|
| 17 |
|
| 18 |
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
|
| 22 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
"""
|
| 24 |
-
|
|
|
|
|
|
|
| 25 |
"""
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
run_port = int(os.getenv("PORT", str(port)))
|
| 28 |
uvicorn = import_module("uvicorn")
|
| 29 |
-
uvicorn.run(
|
| 30 |
|
| 31 |
|
| 32 |
-
__all__ = ["app", "main"]
|
| 33 |
|
| 34 |
if __name__ == "__main__":
|
| 35 |
main()
|
|
|
|
| 1 |
+
"""FastAPI/OpenEnv application entrypoint for AutonomousReturns-v0."""
|
|
|
|
| 2 |
|
| 3 |
+
from __future__ import annotations
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
import os
|
| 6 |
+
from importlib import import_module, util
|
| 7 |
+
from typing import Any
|
| 8 |
|
| 9 |
+
from autonomous_returns_v0 import AutonomousReturnsEnv, ReturnsAction, ReturnsObservation
|
| 10 |
|
| 11 |
+
_openenv_env_server = import_module("openenv.core.env_server")
|
| 12 |
+
create_app = getattr(_openenv_env_server, "create_app")
|
| 13 |
+
create_fastapi_app = getattr(_openenv_env_server, "create_fastapi_app")
|
|
|
|
| 14 |
|
| 15 |
|
| 16 |
+
def _web_requested() -> bool:
|
| 17 |
+
return os.getenv("ENABLE_WEB_INTERFACE", "false").strip().lower() in {
|
| 18 |
+
"1",
|
| 19 |
+
"true",
|
| 20 |
+
"yes",
|
| 21 |
+
}
|
| 22 |
|
| 23 |
|
| 24 |
+
def _gradio_available() -> bool:
|
| 25 |
+
return util.find_spec("gradio") is not None
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def _env_factory() -> AutonomousReturnsEnv:
|
| 29 |
+
task = os.getenv("AUTONOMOUS_RETURNS_TASK", "easy").strip().lower() or "easy"
|
| 30 |
+
return AutonomousReturnsEnv(task=task)
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
def build_app() -> Any:
|
| 34 |
"""
|
| 35 |
+
Build the OpenEnv-compatible app.
|
| 36 |
+
|
| 37 |
+
If web UI is requested but Gradio is not installed, gracefully fall back to API-only.
|
| 38 |
"""
|
| 39 |
+
if _web_requested() and _gradio_available():
|
| 40 |
+
from server.gradio_builder import gradio_builder
|
| 41 |
+
|
| 42 |
+
return create_app(
|
| 43 |
+
env=_env_factory,
|
| 44 |
+
action_cls=ReturnsAction,
|
| 45 |
+
observation_cls=ReturnsObservation,
|
| 46 |
+
env_name="autonomous_returns_v0",
|
| 47 |
+
gradio_builder=gradio_builder,
|
| 48 |
+
)
|
| 49 |
+
|
| 50 |
+
if _web_requested() and not _gradio_available():
|
| 51 |
+
print(
|
| 52 |
+
"ENABLE_WEB_INTERFACE=true but gradio is not installed; serving API-only "
|
| 53 |
+
"(install optional dependency with `.[web]`)."
|
| 54 |
+
)
|
| 55 |
+
|
| 56 |
+
return create_fastapi_app(
|
| 57 |
+
env=_env_factory,
|
| 58 |
+
action_cls=ReturnsAction,
|
| 59 |
+
observation_cls=ReturnsObservation,
|
| 60 |
+
)
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
app = build_app()
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
def main(host: str = "0.0.0.0", port: int = 8000) -> None:
|
| 67 |
run_port = int(os.getenv("PORT", str(port)))
|
| 68 |
uvicorn = import_module("uvicorn")
|
| 69 |
+
uvicorn.run(build_app(), host=host, port=run_port)
|
| 70 |
|
| 71 |
|
| 72 |
+
__all__ = ["app", "build_app", "main"]
|
| 73 |
|
| 74 |
if __name__ == "__main__":
|
| 75 |
main()
|
server/gradio_builder.py
CHANGED
|
@@ -20,9 +20,9 @@ from typing import Any
|
|
| 20 |
|
| 21 |
import gradio as gr
|
| 22 |
|
| 23 |
-
from .
|
| 24 |
-
from .
|
| 25 |
-
from .
|
| 26 |
|
| 27 |
|
| 28 |
def _build_header(task: str, ledger: float, pending_count: int) -> str:
|
|
@@ -478,15 +478,15 @@ def gradio_builder(
|
|
| 478 |
return await _render_ui(web_manager, False)
|
| 479 |
|
| 480 |
async def on_action_discount_15():
|
| 481 |
-
await web_manager.step_environment({"action": "
|
| 482 |
return await _render_ui(web_manager, False)
|
| 483 |
|
| 484 |
async def on_action_discount_30():
|
| 485 |
-
await web_manager.step_environment({"action": "
|
| 486 |
return await _render_ui(web_manager, False)
|
| 487 |
|
| 488 |
async def on_action_discount_50():
|
| 489 |
-
await web_manager.step_environment({"action": "
|
| 490 |
return await _render_ui(web_manager, False)
|
| 491 |
|
| 492 |
async def on_action_refurbish():
|
|
@@ -535,14 +535,12 @@ def gradio_builder(
|
|
| 535 |
provider = str(provider).strip().lower()
|
| 536 |
if provider == "openai" and not os.getenv("OPENAI_API_KEY"):
|
| 537 |
return await _render_ui(web_manager, reveal)
|
| 538 |
-
if provider == "anthropic" and not os.getenv("ANTHROPIC_API_KEY"):
|
| 539 |
-
return await _render_ui(web_manager, reveal)
|
| 540 |
if provider == "google" and not os.getenv("VERTEX_PROJECT_ID"):
|
| 541 |
return await _render_ui(web_manager, reveal)
|
| 542 |
|
| 543 |
resolved_model = (model or "").strip() or (
|
| 544 |
"gpt-4o-mini" if provider == "openai" else (
|
| 545 |
-
"
|
| 546 |
)
|
| 547 |
)
|
| 548 |
config = BaselineRunConfig(provider=provider, model=resolved_model, temperature=float(temp))
|
|
|
|
| 20 |
|
| 21 |
import gradio as gr
|
| 22 |
|
| 23 |
+
from autonomous_returns_v0.baseline import BaselineAgent, BaselineRunConfig
|
| 24 |
+
from autonomous_returns_v0.models import DispositionAction, ReturnsObservation
|
| 25 |
+
from autonomous_returns_v0.policies import HeuristicPolicy
|
| 26 |
|
| 27 |
|
| 28 |
def _build_header(task: str, ledger: float, pending_count: int) -> str:
|
|
|
|
| 478 |
return await _render_ui(web_manager, False)
|
| 479 |
|
| 480 |
async def on_action_discount_15():
|
| 481 |
+
await web_manager.step_environment({"action": "resell_discount_15"})
|
| 482 |
return await _render_ui(web_manager, False)
|
| 483 |
|
| 484 |
async def on_action_discount_30():
|
| 485 |
+
await web_manager.step_environment({"action": "resell_discount_30"})
|
| 486 |
return await _render_ui(web_manager, False)
|
| 487 |
|
| 488 |
async def on_action_discount_50():
|
| 489 |
+
await web_manager.step_environment({"action": "resell_discount_50"})
|
| 490 |
return await _render_ui(web_manager, False)
|
| 491 |
|
| 492 |
async def on_action_refurbish():
|
|
|
|
| 535 |
provider = str(provider).strip().lower()
|
| 536 |
if provider == "openai" and not os.getenv("OPENAI_API_KEY"):
|
| 537 |
return await _render_ui(web_manager, reveal)
|
|
|
|
|
|
|
| 538 |
if provider == "google" and not os.getenv("VERTEX_PROJECT_ID"):
|
| 539 |
return await _render_ui(web_manager, reveal)
|
| 540 |
|
| 541 |
resolved_model = (model or "").strip() or (
|
| 542 |
"gpt-4o-mini" if provider == "openai" else (
|
| 543 |
+
"gemini-2.0-flash"
|
| 544 |
)
|
| 545 |
)
|
| 546 |
config = BaselineRunConfig(provider=provider, model=resolved_model, temperature=float(temp))
|
spaces/Dockerfile
CHANGED
|
@@ -25,4 +25,4 @@ EXPOSE 7860
|
|
| 25 |
HEALTHCHECK --interval=30s --timeout=3s --start-period=15s --retries=3 \
|
| 26 |
CMD curl -fsS http://localhost:7860/health || exit 1
|
| 27 |
|
| 28 |
-
CMD ["uvicorn", "
|
|
|
|
| 25 |
HEALTHCHECK --interval=30s --timeout=3s --start-period=15s --retries=3 \
|
| 26 |
CMD curl -fsS http://localhost:7860/health || exit 1
|
| 27 |
|
| 28 |
+
CMD ["uvicorn", "server.app:app", "--host", "0.0.0.0", "--port", "7860"]
|
spaces/README.md
CHANGED
|
@@ -46,7 +46,7 @@ The project includes an OpenEnv manifest at `openenv.yaml` with:
|
|
| 46 |
|
| 47 |
- `spec_version: 1`
|
| 48 |
- runtime: `fastapi`
|
| 49 |
-
- app: `
|
| 50 |
- typed action/observation/state model references
|
| 51 |
- task definitions and scoring metadata
|
| 52 |
|
|
@@ -58,7 +58,7 @@ From the project root (`returnenv/autonomous_returns_v0`):
|
|
| 58 |
- `pip install .`
|
| 59 |
|
| 60 |
2. Run the server:
|
| 61 |
-
- `uvicorn
|
| 62 |
|
| 63 |
3. Health check:
|
| 64 |
- `GET /health`
|
|
@@ -67,7 +67,7 @@ From the project root (`returnenv/autonomous_returns_v0`):
|
|
| 67 |
|
| 68 |
This Space uses the Dockerfile in `spaces/Dockerfile` and launches:
|
| 69 |
|
| 70 |
-
- `uvicorn
|
| 71 |
|
| 72 |
The container exposes and serves on port `7860`, matching Hugging Face Space configuration.
|
| 73 |
`ENABLE_WEB_INTERFACE=true` is enabled for this Space runtime, so both:
|
|
@@ -100,7 +100,7 @@ It supports async usage and sync wrapper usage through the OpenEnv client base.
|
|
| 100 |
Two baselines are included:
|
| 101 |
|
| 102 |
1. `BaselineAgent` (LLM-based)
|
| 103 |
-
- Supports OpenAI (`OPENAI_API_KEY`) and
|
| 104 |
|
| 105 |
2. `LocalBaselineRunner` (deterministic, no external API)
|
| 106 |
- Reproducible task scoring over fixed seeds.
|
|
@@ -111,12 +111,12 @@ The custom Gradio tab (`Custom`) includes:
|
|
| 111 |
|
| 112 |
- Manual action controls for all 8 disposition actions
|
| 113 |
- Heuristic autoplay (deterministic, no API key required)
|
| 114 |
-
- LLM autoplay (`openai` or `
|
| 115 |
|
| 116 |
LLM autoplay requires:
|
| 117 |
|
| 118 |
- `OPENAI_API_KEY` for OpenAI mode
|
| 119 |
-
- `
|
| 120 |
|
| 121 |
No API keys are entered in the UI.
|
| 122 |
|
|
|
|
| 46 |
|
| 47 |
- `spec_version: 1`
|
| 48 |
- runtime: `fastapi`
|
| 49 |
+
- app: `server.app:app`
|
| 50 |
- typed action/observation/state model references
|
| 51 |
- task definitions and scoring metadata
|
| 52 |
|
|
|
|
| 58 |
- `pip install .`
|
| 59 |
|
| 60 |
2. Run the server:
|
| 61 |
+
- `uvicorn server.app:app --host 0.0.0.0 --port 8000`
|
| 62 |
|
| 63 |
3. Health check:
|
| 64 |
- `GET /health`
|
|
|
|
| 67 |
|
| 68 |
This Space uses the Dockerfile in `spaces/Dockerfile` and launches:
|
| 69 |
|
| 70 |
+
- `uvicorn server.app:app --host 0.0.0.0 --port 7860`
|
| 71 |
|
| 72 |
The container exposes and serves on port `7860`, matching Hugging Face Space configuration.
|
| 73 |
`ENABLE_WEB_INTERFACE=true` is enabled for this Space runtime, so both:
|
|
|
|
| 100 |
Two baselines are included:
|
| 101 |
|
| 102 |
1. `BaselineAgent` (LLM-based)
|
| 103 |
+
- Supports OpenAI (`OPENAI_API_KEY`) and Google Vertex (`VERTEX_PROJECT_ID`).
|
| 104 |
|
| 105 |
2. `LocalBaselineRunner` (deterministic, no external API)
|
| 106 |
- Reproducible task scoring over fixed seeds.
|
|
|
|
| 111 |
|
| 112 |
- Manual action controls for all 8 disposition actions
|
| 113 |
- Heuristic autoplay (deterministic, no API key required)
|
| 114 |
+
- LLM autoplay (`openai` or `google`) using runtime env vars only
|
| 115 |
|
| 116 |
LLM autoplay requires:
|
| 117 |
|
| 118 |
- `OPENAI_API_KEY` for OpenAI mode
|
| 119 |
+
- `VERTEX_PROJECT_ID` for Google mode
|
| 120 |
|
| 121 |
No API keys are entered in the UI.
|
| 122 |
|
tests/test_gradio_builder.py
CHANGED
|
@@ -1,9 +1,11 @@
|
|
| 1 |
from __future__ import annotations
|
| 2 |
|
| 3 |
-
import
|
| 4 |
from openenv.core.env_server.types import EnvironmentMetadata
|
| 5 |
|
| 6 |
-
|
|
|
|
|
|
|
| 7 |
|
| 8 |
|
| 9 |
class _DummyEpisodeState:
|
|
|
|
| 1 |
from __future__ import annotations
|
| 2 |
|
| 3 |
+
import pytest
|
| 4 |
from openenv.core.env_server.types import EnvironmentMetadata
|
| 5 |
|
| 6 |
+
gr = pytest.importorskip("gradio")
|
| 7 |
+
|
| 8 |
+
from server.gradio_builder import gradio_builder
|
| 9 |
|
| 10 |
|
| 11 |
class _DummyEpisodeState:
|
tests/test_server_web_launch.py
CHANGED
|
@@ -3,7 +3,7 @@ from __future__ import annotations
|
|
| 3 |
from fastapi import FastAPI
|
| 4 |
from fastapi.testclient import TestClient
|
| 5 |
|
| 6 |
-
from
|
| 7 |
|
| 8 |
|
| 9 |
def test_build_app_returns_fastapi_instance() -> None:
|
|
|
|
| 3 |
from fastapi import FastAPI
|
| 4 |
from fastapi.testclient import TestClient
|
| 5 |
|
| 6 |
+
from server.app import build_app
|
| 7 |
|
| 8 |
|
| 9 |
def test_build_app_returns_fastapi_instance() -> None:
|
uv.lock
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|