Spaces:
Build error
Build error
Upload folder using huggingface_hub
Browse files- Dockerfile +10 -3
- README.md +128 -19
- src/core/pyproject.toml +12 -2
- src/envs/copy_env/README.md +2 -2
Dockerfile
CHANGED
|
@@ -4,17 +4,24 @@
|
|
| 4 |
# This source code is licensed under the BSD-style license found in the
|
| 5 |
# LICENSE file in the root directory of this source tree.
|
| 6 |
|
| 7 |
-
# Use the
|
|
|
|
|
|
|
|
|
|
| 8 |
FROM ghcr.io/meta-pytorch/openenv-base:latest
|
| 9 |
|
| 10 |
# Copy only what's needed for this environment
|
| 11 |
COPY src/core/ /app/src/core/
|
| 12 |
-
COPY src/envs/
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
# Health check
|
| 15 |
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
|
| 16 |
CMD curl -f http://localhost:8000/health || exit 1
|
| 17 |
|
| 18 |
# Run the FastAPI server
|
| 19 |
-
CMD ["uvicorn", "envs.copy_env.server.app:app", "--host", "0.0.0.0", "--port", "8000"]
|
| 20 |
ENV ENABLE_WEB_INTERFACE=true
|
|
|
|
|
|
|
|
|
| 4 |
# This source code is licensed under the BSD-style license found in the
|
| 5 |
# LICENSE file in the root directory of this source tree.
|
| 6 |
|
| 7 |
+
# Use the standard openenv base image
|
| 8 |
+
# Built from: docker build -t openenv-base:latest -f src/core/containers/images/Dockerfile .
|
| 9 |
+
# In GitHub Actions, this is overridden to use the GHCR base image
|
| 10 |
+
ARG BASE_IMAGE=ghcr.io/meta-pytorch/openenv-base:latest
|
| 11 |
FROM ghcr.io/meta-pytorch/openenv-base:latest
|
| 12 |
|
| 13 |
# Copy only what's needed for this environment
|
| 14 |
COPY src/core/ /app/src/core/
|
| 15 |
+
COPY src/envs/echo_env/ /app/src/envs/echo_env/
|
| 16 |
+
|
| 17 |
+
# Copy README for web interface documentation
|
| 18 |
+
COPY src/envs/echo_env/README.md /app/README.md
|
| 19 |
|
| 20 |
# Health check
|
| 21 |
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
|
| 22 |
CMD curl -f http://localhost:8000/health || exit 1
|
| 23 |
|
| 24 |
# Run the FastAPI server
|
|
|
|
| 25 |
ENV ENABLE_WEB_INTERFACE=true
|
| 26 |
+
|
| 27 |
+
CMD ["uvicorn", "envs.echo_env.server.app:app", "--host", "0.0.0.0", "--port", "8000"]
|
README.md
CHANGED
|
@@ -1,37 +1,146 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom: blue
|
| 5 |
-
colorTo:
|
| 6 |
sdk: docker
|
| 7 |
pinned: false
|
| 8 |
app_port: 8000
|
| 9 |
base_path: /web
|
|
|
|
|
|
|
| 10 |
---
|
| 11 |
|
| 12 |
-
#
|
| 13 |
|
| 14 |
-
|
| 15 |
|
| 16 |
-
##
|
| 17 |
|
| 18 |
-
|
| 19 |
-
Built with FastAPI and OpenEnv framework.
|
| 20 |
|
| 21 |
-
|
|
|
|
| 22 |
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
- **Live Updates**: WebSocket-based real-time updates
|
| 27 |
|
| 28 |
-
|
|
|
|
|
|
|
| 29 |
|
|
|
|
|
|
|
| 30 |
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Echo Environment Server
|
| 3 |
+
emoji: π
|
| 4 |
+
colorFrom: 'blue'
|
| 5 |
+
colorTo: 'gray'
|
| 6 |
sdk: docker
|
| 7 |
pinned: false
|
| 8 |
app_port: 8000
|
| 9 |
base_path: /web
|
| 10 |
+
tags:
|
| 11 |
+
- openenv
|
| 12 |
---
|
| 13 |
|
| 14 |
+
# Echo Environment
|
| 15 |
|
| 16 |
+
A simple test environment that echoes back messages. Perfect for testing the env APIs as well as demonstrating environment usage patterns.
|
| 17 |
|
| 18 |
+
## Quick Start
|
| 19 |
|
| 20 |
+
The simplest way to use the Echo environment is through the `EchoEnv` class:
|
|
|
|
| 21 |
|
| 22 |
+
```python
|
| 23 |
+
from envs.echo_env import EchoAction, EchoEnv
|
| 24 |
|
| 25 |
+
try:
|
| 26 |
+
# Create environment from Docker image
|
| 27 |
+
echo_env = EchoEnv.from_docker_image("echo-env:latest")
|
|
|
|
| 28 |
|
| 29 |
+
# Reset
|
| 30 |
+
result = echo_env.reset()
|
| 31 |
+
print(f"Reset: {result.observation.echoed_message}")
|
| 32 |
|
| 33 |
+
# Send multiple messages
|
| 34 |
+
messages = ["Hello, World!", "Testing echo", "Final message"]
|
| 35 |
|
| 36 |
+
for msg in messages:
|
| 37 |
+
result = echo_env.step(EchoAction(message=msg))
|
| 38 |
+
print(f"Sent: '{msg}'")
|
| 39 |
+
print(f" β Echoed: '{result.observation.echoed_message}'")
|
| 40 |
+
print(f" β Length: {result.observation.message_length}")
|
| 41 |
+
print(f" β Reward: {result.reward}")
|
| 42 |
|
| 43 |
+
finally:
|
| 44 |
+
# Always clean up
|
| 45 |
+
echo_env.close()
|
| 46 |
+
```
|
| 47 |
|
| 48 |
+
That's it! The `EchoEnv.from_docker_image()` method handles:
|
| 49 |
+
- Starting the Docker container
|
| 50 |
+
- Waiting for the server to be ready
|
| 51 |
+
- Connecting to the environment
|
| 52 |
+
- Container cleanup when you call `close()`
|
| 53 |
|
| 54 |
+
## Building the Docker Image
|
| 55 |
+
|
| 56 |
+
Before using the environment, you need to build the Docker image:
|
| 57 |
+
|
| 58 |
+
```bash
|
| 59 |
+
# From project root
|
| 60 |
+
docker build -t echo-env:latest -f src/envs/echo_env/server/Dockerfile .
|
| 61 |
+
```
|
| 62 |
+
|
| 63 |
+
## Environment Details
|
| 64 |
+
|
| 65 |
+
### Action
|
| 66 |
+
**EchoAction**: Contains a single field
|
| 67 |
+
- `message` (str) - The message to echo back
|
| 68 |
+
|
| 69 |
+
### Observation
|
| 70 |
+
**EchoObservation**: Contains the echo response and metadata
|
| 71 |
+
- `echoed_message` (str) - The message echoed back
|
| 72 |
+
- `message_length` (int) - Length of the message
|
| 73 |
+
- `reward` (float) - Reward based on message length (length Γ 0.1)
|
| 74 |
+
- `done` (bool) - Always False for echo environment
|
| 75 |
+
- `metadata` (dict) - Additional info like step count
|
| 76 |
+
|
| 77 |
+
### Reward
|
| 78 |
+
The reward is calculated as: `message_length Γ 0.1`
|
| 79 |
+
- "Hi" β reward: 0.2
|
| 80 |
+
- "Hello, World!" β reward: 1.3
|
| 81 |
+
- Empty message β reward: 0.0
|
| 82 |
+
|
| 83 |
+
## Advanced Usage
|
| 84 |
+
|
| 85 |
+
### Connecting to an Existing Server
|
| 86 |
+
|
| 87 |
+
If you already have an Echo environment server running, you can connect directly:
|
| 88 |
+
|
| 89 |
+
```python
|
| 90 |
+
from envs.echo_env import EchoEnv
|
| 91 |
+
|
| 92 |
+
# Connect to existing server
|
| 93 |
+
echo_env = EchoEnv(base_url="<ENV_HTTP_URL_HERE>")
|
| 94 |
+
|
| 95 |
+
# Use as normal
|
| 96 |
+
result = echo_env.reset()
|
| 97 |
+
result = echo_env.step(EchoAction(message="Hello!"))
|
| 98 |
+
```
|
| 99 |
+
|
| 100 |
+
Note: When connecting to an existing server, `echo_env.close()` will NOT stop the server.
|
| 101 |
+
|
| 102 |
+
## Development & Testing
|
| 103 |
+
|
| 104 |
+
### Direct Environment Testing
|
| 105 |
+
|
| 106 |
+
Test the environment logic directly without starting the HTTP server:
|
| 107 |
+
|
| 108 |
+
```bash
|
| 109 |
+
# From the server directory
|
| 110 |
+
python3 src/envs/echo_env/server/test_echo_env.py
|
| 111 |
+
```
|
| 112 |
+
|
| 113 |
+
This verifies that:
|
| 114 |
+
- Environment resets correctly
|
| 115 |
+
- Step executes actions properly
|
| 116 |
+
- State tracking works
|
| 117 |
+
- Rewards are calculated correctly
|
| 118 |
+
|
| 119 |
+
### Running the Full Example
|
| 120 |
+
|
| 121 |
+
Run the complete example that demonstrates the full workflow:
|
| 122 |
+
|
| 123 |
+
```bash
|
| 124 |
+
python3 examples/local_echo_env.py
|
| 125 |
+
```
|
| 126 |
+
|
| 127 |
+
This example shows:
|
| 128 |
+
- Creating an environment from a Docker image
|
| 129 |
+
- Resetting and stepping through the environment
|
| 130 |
+
- Automatic cleanup with `close()`
|
| 131 |
+
|
| 132 |
+
## Project Structure
|
| 133 |
+
|
| 134 |
+
```
|
| 135 |
+
echo_env/
|
| 136 |
+
βββ __init__.py # Module exports
|
| 137 |
+
βββ README.md # This file
|
| 138 |
+
βββ client.py # EchoEnv client implementation
|
| 139 |
+
βββ models.py # Action and Observation models
|
| 140 |
+
βββ server/
|
| 141 |
+
βββ __init__.py # Server module exports
|
| 142 |
+
βββ echo_environment.py # Core environment logic
|
| 143 |
+
βββ app.py # FastAPI application
|
| 144 |
+
βββ test_echo_env.py # Direct environment tests
|
| 145 |
+
βββ Dockerfile # Container image definition
|
| 146 |
+
```
|
src/core/pyproject.toml
CHANGED
|
@@ -18,8 +18,14 @@ dependencies = [
|
|
| 18 |
"requests>=2.25.0",
|
| 19 |
"fastapi>=0.104.0",
|
| 20 |
"uvicorn>=0.24.0",
|
|
|
|
|
|
|
|
|
|
| 21 |
]
|
| 22 |
|
|
|
|
|
|
|
|
|
|
| 23 |
[project.optional-dependencies]
|
| 24 |
dev = [
|
| 25 |
"pytest>=7.0.0",
|
|
@@ -41,6 +47,10 @@ packages = [
|
|
| 41 |
"openenv_core.containers",
|
| 42 |
"openenv_core.containers.runtime",
|
| 43 |
"openenv_core.env_server",
|
| 44 |
-
"openenv_core.tools"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
]
|
| 46 |
-
package-dir = {"openenv_core" = "."}
|
|
|
|
| 18 |
"requests>=2.25.0",
|
| 19 |
"fastapi>=0.104.0",
|
| 20 |
"uvicorn>=0.24.0",
|
| 21 |
+
"huggingface_hub>=0.20.0",
|
| 22 |
+
"rich>=13.0.0",
|
| 23 |
+
"typer>=0.12.0",
|
| 24 |
]
|
| 25 |
|
| 26 |
+
[project.scripts]
|
| 27 |
+
openenv = "openenv_cli.__main__:main"
|
| 28 |
+
|
| 29 |
[project.optional-dependencies]
|
| 30 |
dev = [
|
| 31 |
"pytest>=7.0.0",
|
|
|
|
| 47 |
"openenv_core.containers",
|
| 48 |
"openenv_core.containers.runtime",
|
| 49 |
"openenv_core.env_server",
|
| 50 |
+
"openenv_core.tools",
|
| 51 |
+
"openenv_cli",
|
| 52 |
+
"openenv_cli.commands",
|
| 53 |
+
"openenv_cli.core",
|
| 54 |
+
"openenv_cli.utils",
|
| 55 |
]
|
| 56 |
+
package-dir = {"openenv_core" = ".", "openenv_cli" = "../openenv_cli"}
|
src/envs/copy_env/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
| 1 |
---
|
| 2 |
title: Echo Environment Server
|
| 3 |
emoji: π
|
| 4 |
-
colorFrom: '
|
| 5 |
-
colorTo: '
|
| 6 |
sdk: docker
|
| 7 |
pinned: false
|
| 8 |
app_port: 8000
|
|
|
|
| 1 |
---
|
| 2 |
title: Echo Environment Server
|
| 3 |
emoji: π
|
| 4 |
+
colorFrom: 'blue'
|
| 5 |
+
colorTo: 'gray'
|
| 6 |
sdk: docker
|
| 7 |
pinned: false
|
| 8 |
app_port: 8000
|