CoolFace
Apppublic

spk-22/Context_Aware_Content_Moderation_Environment_using_OpenEnv

sourceHugging Facemitupdated 6mo agoView on Hugging Face
0likes
client.py59 linesDownload Raw Back to root
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 the5# LICENSE file in the root directory of this source tree.6 7 8"""Content Moderation Environment Client."""9 10from typing import Dict11 12from openenv.core import EnvClient13from openenv.core.client_types import StepResult14from openenv.core.env_server.types import State15 16from .models import ContentModerationAction, ContentModerationObservation17 18 19class ContentModerationEnv(20    EnvClient[ContentModerationAction, ContentModerationObservation, State]21):22    """23    Client for the Content Moderation Environment.24    """25 26    def _step_payload(self, action: ContentModerationAction) -> Dict:27        """28        Convert ContentModerationAction to JSON payload for step message.29        """30        return {31            "decision": action.decision,   # ✅ FIXED32        }33 34    def _parse_result(self, payload: Dict) -> StepResult[ContentModerationObservation]:35        """36        Parse server response into StepResult.37        """38        obs_data = payload.get("observation", {})  # ✅ FIXED39 40        observation = ContentModerationObservation(41            content=obs_data.get("content"),       # ✅ FIXED42            context=obs_data.get("context"),43            intent=obs_data.get("intent"),44        )45 46        return StepResult(47            observation=observation,48            reward=payload.get("reward"),49            done=payload.get("done", False),50        )51 52    def _parse_state(self, payload: Dict) -> State:53        """54        Parse server response into State object.55        """56        return State(57            episode_id=payload.get("episode_id"),58            step_count=payload.get("step_count", 0),59        )