Delete server/support_env_environment.py
Browse files
server/support_env_environment.py
DELETED
|
@@ -1,104 +0,0 @@
|
|
| 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 |
-
"""
|
| 8 |
-
Support Env Environment Implementation.
|
| 9 |
-
|
| 10 |
-
A simple test environment that echoes back messages sent to it.
|
| 11 |
-
Perfect for testing HTTP server infrastructure.
|
| 12 |
-
"""
|
| 13 |
-
|
| 14 |
-
from uuid import uuid4
|
| 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 SupportAction, SupportObservation
|
| 21 |
-
except ImportError:
|
| 22 |
-
from models import SupportAction, SupportObservation
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
class SupportEnvironment(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 = SupportEnvironment()
|
| 34 |
-
>>> obs = env.reset()
|
| 35 |
-
>>> print(obs.echoed_message) # "Support Env environment ready!"
|
| 36 |
-
>>>
|
| 37 |
-
>>> obs = env.step(SupportAction(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 support_env environment."""
|
| 50 |
-
self._state = State(episode_id=str(uuid4()), step_count=0)
|
| 51 |
-
self._reset_count = 0
|
| 52 |
-
|
| 53 |
-
def reset(self) -> SupportObservation:
|
| 54 |
-
"""
|
| 55 |
-
Reset the environment.
|
| 56 |
-
|
| 57 |
-
Returns:
|
| 58 |
-
SupportObservation with a ready message
|
| 59 |
-
"""
|
| 60 |
-
self._state = State(episode_id=str(uuid4()), step_count=0)
|
| 61 |
-
self._reset_count += 1
|
| 62 |
-
|
| 63 |
-
return SupportObservation(
|
| 64 |
-
echoed_message="Support Env environment ready!",
|
| 65 |
-
message_length=0,
|
| 66 |
-
done=False,
|
| 67 |
-
reward=0.0,
|
| 68 |
-
)
|
| 69 |
-
|
| 70 |
-
def step(self, action: SupportAction) -> SupportObservation: # type: ignore[override]
|
| 71 |
-
"""
|
| 72 |
-
Execute a step in the environment by echoing the message.
|
| 73 |
-
|
| 74 |
-
Args:
|
| 75 |
-
action: SupportAction containing the message to echo
|
| 76 |
-
|
| 77 |
-
Returns:
|
| 78 |
-
SupportObservation 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 SupportObservation(
|
| 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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|