Spaces:
Sleeping
Sleeping
Delete server
Browse files- server/__init__.py +0 -1
- server/app.py +0 -29
- server/environment.py +0 -84
- server/models.py +0 -40
server/__init__.py
DELETED
|
@@ -1 +0,0 @@
|
|
| 1 |
-
"""HTTP server package for Enterprise Support Ticket Triage."""
|
|
|
|
|
|
server/app.py
DELETED
|
@@ -1,29 +0,0 @@
|
|
| 1 |
-
from __future__ import annotations
|
| 2 |
-
|
| 3 |
-
import os
|
| 4 |
-
|
| 5 |
-
from openenv.core.env_server.http_server import create_app
|
| 6 |
-
|
| 7 |
-
from .environment import SupportTriageServerEnvironment
|
| 8 |
-
from .models import SupportTriageAction, SupportTriageObservation
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
app = create_app(
|
| 12 |
-
SupportTriageServerEnvironment,
|
| 13 |
-
SupportTriageAction,
|
| 14 |
-
SupportTriageObservation,
|
| 15 |
-
env_name="enterprise-support-ticket-triage",
|
| 16 |
-
max_concurrent_envs=1,
|
| 17 |
-
)
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
def main(host: str = "0.0.0.0", port: int | None = None) -> None:
|
| 21 |
-
import uvicorn
|
| 22 |
-
|
| 23 |
-
if port is None:
|
| 24 |
-
port = int(os.getenv("PORT", "8000"))
|
| 25 |
-
uvicorn.run(app, host=host, port=port)
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
if __name__ == "__main__":
|
| 29 |
-
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
server/environment.py
DELETED
|
@@ -1,84 +0,0 @@
|
|
| 1 |
-
from __future__ import annotations
|
| 2 |
-
|
| 3 |
-
from uuid import uuid4
|
| 4 |
-
|
| 5 |
-
from openenv.core.env_server.interfaces import Environment
|
| 6 |
-
from openenv.core.env_server.types import State
|
| 7 |
-
|
| 8 |
-
from env.models import Action as NativeAction
|
| 9 |
-
from env.support_env import EnterpriseSupportTicketTriageEnv
|
| 10 |
-
|
| 11 |
-
from .models import SupportTriageAction, SupportTriageObservation
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
class SupportTriageServerEnvironment(Environment):
|
| 15 |
-
"""OpenEnv HTTP adapter around the local Python RL environment."""
|
| 16 |
-
|
| 17 |
-
SUPPORTS_CONCURRENT_SESSIONS: bool = False
|
| 18 |
-
|
| 19 |
-
def __init__(self):
|
| 20 |
-
super().__init__()
|
| 21 |
-
self._env = EnterpriseSupportTicketTriageEnv()
|
| 22 |
-
self._state = State(episode_id=str(uuid4()), step_count=0)
|
| 23 |
-
|
| 24 |
-
def reset(self, seed: int | None = None, episode_id: str | None = None, **kwargs) -> SupportTriageObservation:
|
| 25 |
-
task_id = kwargs.get("task_id")
|
| 26 |
-
observation = self._env.reset(task_id=task_id)
|
| 27 |
-
episode = episode_id or observation.ticket_id or str(uuid4())
|
| 28 |
-
self._state = State(episode_id=episode, step_count=observation.step_count)
|
| 29 |
-
return self._map_observation(observation, reward=0.0, done=False, metadata={"task_id": observation.task_id})
|
| 30 |
-
|
| 31 |
-
def step(self, action: SupportTriageAction, timeout_s: float | None = None, **kwargs) -> SupportTriageObservation:
|
| 32 |
-
native_action = NativeAction.model_validate(
|
| 33 |
-
{
|
| 34 |
-
"action_type": action.action_type,
|
| 35 |
-
"message": action.message,
|
| 36 |
-
"queue": action.queue,
|
| 37 |
-
"priority": action.priority,
|
| 38 |
-
"tags": action.tags,
|
| 39 |
-
"resolution_code": action.resolution_code,
|
| 40 |
-
}
|
| 41 |
-
)
|
| 42 |
-
observation, reward, done, info = self._env.step(native_action)
|
| 43 |
-
self._state.step_count = observation.step_count
|
| 44 |
-
return self._map_observation(
|
| 45 |
-
observation,
|
| 46 |
-
reward=reward.value,
|
| 47 |
-
done=done,
|
| 48 |
-
metadata={
|
| 49 |
-
"reward_components": reward.components,
|
| 50 |
-
"reward_reason": reward.reason,
|
| 51 |
-
"info": info,
|
| 52 |
-
},
|
| 53 |
-
)
|
| 54 |
-
|
| 55 |
-
@property
|
| 56 |
-
def state(self) -> State:
|
| 57 |
-
return self._state
|
| 58 |
-
|
| 59 |
-
def _map_observation(
|
| 60 |
-
self,
|
| 61 |
-
observation,
|
| 62 |
-
reward: float,
|
| 63 |
-
done: bool,
|
| 64 |
-
metadata: dict,
|
| 65 |
-
) -> SupportTriageObservation:
|
| 66 |
-
return SupportTriageObservation(
|
| 67 |
-
task_id=observation.task_id,
|
| 68 |
-
difficulty=observation.difficulty,
|
| 69 |
-
ticket_id=observation.ticket_id,
|
| 70 |
-
subject=observation.subject,
|
| 71 |
-
customer_message=observation.customer_message,
|
| 72 |
-
extracted_entities=observation.extracted_entities,
|
| 73 |
-
current_status=observation.current_status.value,
|
| 74 |
-
current_queue=observation.current_queue,
|
| 75 |
-
current_priority=observation.current_priority.value,
|
| 76 |
-
conversation_history=[turn.model_dump() for turn in observation.conversation_history],
|
| 77 |
-
required_missing_fields=observation.required_missing_fields,
|
| 78 |
-
last_action_error=observation.last_action_error,
|
| 79 |
-
step_count=observation.step_count,
|
| 80 |
-
max_steps_remaining=observation.max_steps_remaining,
|
| 81 |
-
reward=reward,
|
| 82 |
-
done=done,
|
| 83 |
-
metadata=metadata,
|
| 84 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
server/models.py
DELETED
|
@@ -1,40 +0,0 @@
|
|
| 1 |
-
from __future__ import annotations
|
| 2 |
-
|
| 3 |
-
from typing import Literal
|
| 4 |
-
|
| 5 |
-
from openenv.core.env_server.types import Action, Observation
|
| 6 |
-
from pydantic import Field
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
class SupportTriageAction(Action):
|
| 10 |
-
action_type: Literal[
|
| 11 |
-
"classify",
|
| 12 |
-
"reply",
|
| 13 |
-
"escalate",
|
| 14 |
-
"close",
|
| 15 |
-
"request_info",
|
| 16 |
-
"update_priority",
|
| 17 |
-
"assign_queue",
|
| 18 |
-
]
|
| 19 |
-
message: str = ""
|
| 20 |
-
queue: str | None = None
|
| 21 |
-
priority: Literal["low", "normal", "high", "urgent"] | None = None
|
| 22 |
-
tags: list[str] = Field(default_factory=list)
|
| 23 |
-
resolution_code: str | None = None
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
class SupportTriageObservation(Observation):
|
| 27 |
-
task_id: str
|
| 28 |
-
difficulty: str
|
| 29 |
-
ticket_id: str
|
| 30 |
-
subject: str
|
| 31 |
-
customer_message: str
|
| 32 |
-
extracted_entities: dict = Field(default_factory=dict)
|
| 33 |
-
current_status: str
|
| 34 |
-
current_queue: str
|
| 35 |
-
current_priority: str
|
| 36 |
-
conversation_history: list[dict] = Field(default_factory=list)
|
| 37 |
-
required_missing_fields: list[str] = Field(default_factory=list)
|
| 38 |
-
last_action_error: str | None = None
|
| 39 |
-
step_count: int
|
| 40 |
-
max_steps_remaining: int
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|