tether007 commited on
Commit ·
12b4e42
1
Parent(s): 8ff5feb
fix openenv-core dep
Browse files- trade_env/pyproject.toml +11 -27
- trade_env/server/__init__.py +1 -4
- trade_env/server/environment.py +5 -101
trade_env/pyproject.toml
CHANGED
|
@@ -1,45 +1,29 @@
|
|
| 1 |
-
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
| 2 |
-
# All rights reserved.
|
| 3 |
-
#
|
| 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 |
[build-system]
|
| 8 |
requires = ["setuptools>=45", "wheel"]
|
| 9 |
build-backend = "setuptools.build_meta"
|
| 10 |
|
| 11 |
[project]
|
| 12 |
-
name = "
|
| 13 |
version = "0.1.0"
|
| 14 |
-
description = "
|
| 15 |
-
requires-python = ">=3.
|
| 16 |
dependencies = [
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
"
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
# "numpy>=1.19.0",
|
| 25 |
-
# "torch>=2.0.0",
|
| 26 |
-
# "gymnasium>=0.29.0",
|
| 27 |
-
# "openspiel>=1.0.0",
|
| 28 |
-
# "smolagents>=1.22.0,<2",
|
| 29 |
]
|
| 30 |
|
| 31 |
[project.optional-dependencies]
|
| 32 |
dev = [
|
| 33 |
"pytest>=8.0.0",
|
| 34 |
-
"pytest-cov>=4.0.0",
|
| 35 |
]
|
| 36 |
|
| 37 |
[project.scripts]
|
| 38 |
-
# Server entry point - enables running via: uv run --project . server
|
| 39 |
-
# or: python -m trade_env.server.app
|
| 40 |
server = "trade_env.server.app:main"
|
| 41 |
|
| 42 |
[tool.setuptools]
|
| 43 |
-
|
| 44 |
-
packages = ["trade_env", "trade_env.server"]
|
| 45 |
-
package-dir = { "trade_env" = ".", "trade_env.server" = "server" }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
[build-system]
|
| 2 |
requires = ["setuptools>=45", "wheel"]
|
| 3 |
build-backend = "setuptools.build_meta"
|
| 4 |
|
| 5 |
[project]
|
| 6 |
+
name = "trade-env"
|
| 7 |
version = "0.1.0"
|
| 8 |
+
description = "Retail Trader Behavior Coach - RL agent that intervenes on bad trading behavior"
|
| 9 |
+
requires-python = ">=3.11"
|
| 10 |
dependencies = [
|
| 11 |
+
"openenv-core>=0.2.2",
|
| 12 |
+
"fastapi>=0.115.0",
|
| 13 |
+
"uvicorn>=0.24.0",
|
| 14 |
+
"pydantic>=2.0.0",
|
| 15 |
+
"torch>=2.0.0",
|
| 16 |
+
"python-dotenv>=1.0.0",
|
| 17 |
+
"openai>=1.0.0",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
]
|
| 19 |
|
| 20 |
[project.optional-dependencies]
|
| 21 |
dev = [
|
| 22 |
"pytest>=8.0.0",
|
|
|
|
| 23 |
]
|
| 24 |
|
| 25 |
[project.scripts]
|
|
|
|
|
|
|
| 26 |
server = "trade_env.server.app:main"
|
| 27 |
|
| 28 |
[tool.setuptools]
|
| 29 |
+
packages = ["trade_env", "trade_env.server", "trade_env.env", "trade_env.schemas", "trade_env.agent"]
|
|
|
|
|
|
trade_env/server/__init__.py
CHANGED
|
@@ -4,8 +4,5 @@
|
|
| 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 |
-
"""Trade Env environment server components."""
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
__all__ = ["TradeEnvironment"]
|
|
|
|
| 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 |
|
| 8 |
+
__all__ = []
|
|
|
|
|
|
trade_env/server/environment.py
CHANGED
|
@@ -1,104 +1,8 @@
|
|
| 1 |
-
|
| 2 |
-
# All rights reserved.
|
| 3 |
-
#
|
| 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 |
-
|
| 8 |
-
Trade Env Environment Implementation.
|
| 9 |
|
| 10 |
-
|
| 11 |
-
Perfect for testing HTTP server infrastructure.
|
| 12 |
-
"""
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
from openenv.core.env_server.interfaces import Environment
|
| 17 |
-
from openenv.core.env_server.types import State
|
| 18 |
-
|
| 19 |
-
try:
|
| 20 |
-
from ..models import TradeAction, TradeObservation
|
| 21 |
-
except ImportError:
|
| 22 |
-
from models import TradeAction, TradeObservation
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
class TradeEnvironment(Environment):
|
| 26 |
-
"""
|
| 27 |
-
A simple echo environment that echoes back messages.
|
| 28 |
-
|
| 29 |
-
This environment is designed for testing the HTTP server infrastructure.
|
| 30 |
-
It maintains minimal state and simply echoes back whatever message it receives.
|
| 31 |
-
|
| 32 |
-
Example:
|
| 33 |
-
>>> env = TradeEnvironment()
|
| 34 |
-
>>> obs = env.reset()
|
| 35 |
-
>>> print(obs.echoed_message) # "Trade Env environment ready!"
|
| 36 |
-
>>>
|
| 37 |
-
>>> obs = env.step(TradeAction(message="Hello"))
|
| 38 |
-
>>> print(obs.echoed_message) # "Hello"
|
| 39 |
-
>>> print(obs.message_length) # 5
|
| 40 |
-
"""
|
| 41 |
-
|
| 42 |
-
# Enable concurrent WebSocket sessions.
|
| 43 |
-
# Set to True if your environment isolates state between instances.
|
| 44 |
-
# When True, multiple WebSocket clients can connect simultaneously, each
|
| 45 |
-
# getting their own environment instance (when using factory mode in app.py).
|
| 46 |
-
SUPPORTS_CONCURRENT_SESSIONS: bool = True
|
| 47 |
-
|
| 48 |
-
def __init__(self):
|
| 49 |
-
"""Initialize the trade_env environment."""
|
| 50 |
-
self._state = State(episode_id=str(uuid4()), step_count=0)
|
| 51 |
-
self._reset_count = 0
|
| 52 |
-
|
| 53 |
-
def reset(self) -> TradeObservation:
|
| 54 |
-
"""
|
| 55 |
-
Reset the environment.
|
| 56 |
-
|
| 57 |
-
Returns:
|
| 58 |
-
TradeObservation with a ready message
|
| 59 |
-
"""
|
| 60 |
-
self._state = State(episode_id=str(uuid4()), step_count=0)
|
| 61 |
-
self._reset_count += 1
|
| 62 |
-
|
| 63 |
-
return TradeObservation(
|
| 64 |
-
echoed_message="Trade Env environment ready!",
|
| 65 |
-
message_length=0,
|
| 66 |
-
done=False,
|
| 67 |
-
reward=0.0,
|
| 68 |
-
)
|
| 69 |
-
|
| 70 |
-
def step(self, action: TradeAction) -> TradeObservation: # type: ignore[override]
|
| 71 |
-
"""
|
| 72 |
-
Execute a step in the environment by echoing the message.
|
| 73 |
-
|
| 74 |
-
Args:
|
| 75 |
-
action: TradeAction containing the message to echo
|
| 76 |
-
|
| 77 |
-
Returns:
|
| 78 |
-
TradeObservation with the echoed message and its length
|
| 79 |
-
"""
|
| 80 |
-
self._state.step_count += 1
|
| 81 |
-
|
| 82 |
-
message = action.message
|
| 83 |
-
length = len(message)
|
| 84 |
-
|
| 85 |
-
# Simple reward: longer messages get higher rewards
|
| 86 |
-
reward = length * 0.1
|
| 87 |
-
|
| 88 |
-
return TradeObservation(
|
| 89 |
-
echoed_message=message,
|
| 90 |
-
message_length=length,
|
| 91 |
-
done=False,
|
| 92 |
-
reward=reward,
|
| 93 |
-
metadata={"original_message": message, "step": self._state.step_count},
|
| 94 |
-
)
|
| 95 |
-
|
| 96 |
-
@property
|
| 97 |
-
def state(self) -> State:
|
| 98 |
-
"""
|
| 99 |
-
Get the current environment state.
|
| 100 |
-
|
| 101 |
-
Returns:
|
| 102 |
-
Current State with episode_id and step_count
|
| 103 |
-
"""
|
| 104 |
-
return self._state
|
|
|
|
| 1 |
+
"""Trade Env Server Environment - wraps CoachEnv for OpenEnv server."""
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
+
from trade_env.env.coach_env import CoachEnv
|
|
|
|
| 4 |
|
| 5 |
+
env = CoachEnv()
|
|
|
|
|
|
|
| 6 |
|
| 7 |
+
def get_env() -> CoachEnv:
|
| 8 |
+
return env
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|