Delete server
Browse files- server/Dockerfile +0 -80
- server/__init__.py +0 -11
- server/__pycache__/__init__.cpython-313.pyc +0 -0
- server/__pycache__/app.cpython-313.pyc +0 -0
- server/__pycache__/gov_env_environment.cpython-313.pyc +0 -0
- server/app.py +0 -21
- server/gov_env_environment.py +0 -400
- server/gov_env_environment.py.backup +0 -104
- server/requirements.txt +0 -6
server/Dockerfile
DELETED
|
@@ -1,80 +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 |
-
# Multi-stage build using openenv-base
|
| 8 |
-
# This Dockerfile is flexible and works for both:
|
| 9 |
-
# - In-repo environments (with local OpenEnv sources)
|
| 10 |
-
# - Standalone environments (with openenv from PyPI/Git)
|
| 11 |
-
# The build script (openenv build) handles context detection and sets appropriate build args.
|
| 12 |
-
|
| 13 |
-
ARG BASE_IMAGE=ghcr.io/meta-pytorch/openenv-base:latest
|
| 14 |
-
FROM ${BASE_IMAGE} AS builder
|
| 15 |
-
|
| 16 |
-
WORKDIR /app
|
| 17 |
-
|
| 18 |
-
# Ensure git is available (required for installing dependencies from VCS)
|
| 19 |
-
RUN apt-get update && \
|
| 20 |
-
apt-get install -y --no-install-recommends git && \
|
| 21 |
-
rm -rf /var/lib/apt/lists/*
|
| 22 |
-
|
| 23 |
-
# Build argument to control whether we're building standalone or in-repo
|
| 24 |
-
ARG BUILD_MODE=in-repo
|
| 25 |
-
ARG ENV_NAME=gov_env
|
| 26 |
-
|
| 27 |
-
# Copy environment code (always at root of build context)
|
| 28 |
-
COPY . /app/env
|
| 29 |
-
|
| 30 |
-
# For in-repo builds, openenv is already vendored in the build context
|
| 31 |
-
# For standalone builds, openenv will be installed via pyproject.toml
|
| 32 |
-
WORKDIR /app/env
|
| 33 |
-
|
| 34 |
-
# Ensure uv is available (for local builds where base image lacks it)
|
| 35 |
-
RUN if ! command -v uv >/dev/null 2>&1; then \
|
| 36 |
-
curl -LsSf https://astral.sh/uv/install.sh | sh && \
|
| 37 |
-
mv /root/.local/bin/uv /usr/local/bin/uv && \
|
| 38 |
-
mv /root/.local/bin/uvx /usr/local/bin/uvx; \
|
| 39 |
-
fi
|
| 40 |
-
|
| 41 |
-
# Install dependencies using uv sync
|
| 42 |
-
# If uv.lock exists, use it; otherwise resolve on the fly
|
| 43 |
-
RUN --mount=type=cache,target=/root/.cache/uv \
|
| 44 |
-
if [ -f uv.lock ]; then \
|
| 45 |
-
uv sync --frozen --no-install-project --no-editable; \
|
| 46 |
-
else \
|
| 47 |
-
uv sync --no-install-project --no-editable; \
|
| 48 |
-
fi
|
| 49 |
-
|
| 50 |
-
RUN --mount=type=cache,target=/root/.cache/uv \
|
| 51 |
-
if [ -f uv.lock ]; then \
|
| 52 |
-
uv sync --frozen --no-editable; \
|
| 53 |
-
else \
|
| 54 |
-
uv sync --no-editable; \
|
| 55 |
-
fi
|
| 56 |
-
|
| 57 |
-
# Final runtime stage
|
| 58 |
-
FROM ${BASE_IMAGE}
|
| 59 |
-
|
| 60 |
-
WORKDIR /app
|
| 61 |
-
|
| 62 |
-
# Copy the virtual environment from builder
|
| 63 |
-
COPY --from=builder /app/env/.venv /app/.venv
|
| 64 |
-
|
| 65 |
-
# Copy the environment code
|
| 66 |
-
COPY --from=builder /app/env /app/env
|
| 67 |
-
|
| 68 |
-
# Set PATH to use the virtual environment
|
| 69 |
-
ENV PATH="/app/.venv/bin:$PATH"
|
| 70 |
-
|
| 71 |
-
# Set PYTHONPATH so imports work correctly
|
| 72 |
-
ENV PYTHONPATH="/app/env:$PYTHONPATH"
|
| 73 |
-
|
| 74 |
-
# Health check
|
| 75 |
-
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
|
| 76 |
-
CMD curl -f http://localhost:8000/health || exit 1
|
| 77 |
-
|
| 78 |
-
# Run the FastAPI server
|
| 79 |
-
# The module path is constructed to work with the /app/env structure
|
| 80 |
-
CMD ["sh", "-c", "cd /app/env && uvicorn server.app:app --host 0.0.0.0 --port 8000"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
server/__init__.py
DELETED
|
@@ -1,11 +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 |
-
"""Gov Env environment server components."""
|
| 8 |
-
|
| 9 |
-
from .gov_env_environment import GovEnvironment
|
| 10 |
-
|
| 11 |
-
__all__ = ["GovEnvironment"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
server/__pycache__/__init__.cpython-313.pyc
DELETED
|
Binary file (326 Bytes)
|
|
|
server/__pycache__/app.cpython-313.pyc
DELETED
|
Binary file (2.8 kB)
|
|
|
server/__pycache__/gov_env_environment.cpython-313.pyc
DELETED
|
Binary file (14.8 kB)
|
|
|
server/app.py
DELETED
|
@@ -1,21 +0,0 @@
|
|
| 1 |
-
try:
|
| 2 |
-
from openenv.core.env_server.http_server import create_app
|
| 3 |
-
except Exception as e:
|
| 4 |
-
raise ImportError("openenv is required. Install: pip install openenv-core") from e
|
| 5 |
-
|
| 6 |
-
from models import GovAction, GovObservation
|
| 7 |
-
from server.gov_env_environment import GovEnvironment
|
| 8 |
-
|
| 9 |
-
app = create_app(
|
| 10 |
-
GovEnvironment,
|
| 11 |
-
GovAction,
|
| 12 |
-
GovObservation,
|
| 13 |
-
env_name="gov_env",
|
| 14 |
-
max_concurrent_envs=1,
|
| 15 |
-
)
|
| 16 |
-
|
| 17 |
-
if __name__ == "__main__":
|
| 18 |
-
import uvicorn
|
| 19 |
-
import os
|
| 20 |
-
port = int(os.environ.get("PORT", 7860))
|
| 21 |
-
uvicorn.run(app, host="0.0.0.0", port=port)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
server/gov_env_environment.py
DELETED
|
@@ -1,400 +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 |
-
Government Service Application Assistant Environment Implementation.
|
| 9 |
-
|
| 10 |
-
A simple implementation that simulates government service document assistance.
|
| 11 |
-
"""
|
| 12 |
-
|
| 13 |
-
from uuid import uuid4
|
| 14 |
-
from typing import Dict, Any, Optional
|
| 15 |
-
|
| 16 |
-
from openenv.core.env_server.interfaces import Environment
|
| 17 |
-
from openenv.core.env_server.types import State
|
| 18 |
-
|
| 19 |
-
from models import GovAction, GovObservation
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
class GovEnvironment(Environment):
|
| 23 |
-
"""
|
| 24 |
-
Government Service Application Assistant Environment.
|
| 25 |
-
|
| 26 |
-
This environment simulates an AI assistant helping users with government service applications.
|
| 27 |
-
"""
|
| 28 |
-
|
| 29 |
-
SUPPORTS_CONCURRENT_SESSIONS: bool = True
|
| 30 |
-
|
| 31 |
-
def __init__(self):
|
| 32 |
-
"""Initialize the government service environment."""
|
| 33 |
-
self._state = State(episode_id=str(uuid4()), step_count=0)
|
| 34 |
-
self._service_type: Optional[str] = None
|
| 35 |
-
self._current_stage = "service_selection"
|
| 36 |
-
self._required_documents: list[Dict[str, Any]] = []
|
| 37 |
-
self._submitted_documents: list[Dict[str, Any]] = []
|
| 38 |
-
self._validation_results: Optional[Dict[str, Any]] = None
|
| 39 |
-
self._correction_suggestions: list[Dict[str, Any]] = []
|
| 40 |
-
self._application_id: Optional[str] = None
|
| 41 |
-
self._done = False
|
| 42 |
-
|
| 43 |
-
def reset(self) -> GovObservation:
|
| 44 |
-
"""
|
| 45 |
-
Reset the environment to initial state.
|
| 46 |
-
|
| 47 |
-
Returns:
|
| 48 |
-
GovObservation with welcome message
|
| 49 |
-
"""
|
| 50 |
-
self._state = State(episode_id=str(uuid4()), step_count=0)
|
| 51 |
-
self._service_type = None
|
| 52 |
-
self._current_stage = "service_selection"
|
| 53 |
-
self._required_documents = []
|
| 54 |
-
self._submitted_documents = []
|
| 55 |
-
self._validation_results = None
|
| 56 |
-
self._correction_suggestions = []
|
| 57 |
-
self._application_id = None
|
| 58 |
-
self._done = False
|
| 59 |
-
|
| 60 |
-
return GovObservation(
|
| 61 |
-
message="Government Service Assistant ready. Please select a service to begin.",
|
| 62 |
-
current_stage=self._current_stage,
|
| 63 |
-
reward=0.0,
|
| 64 |
-
done=False,
|
| 65 |
-
)
|
| 66 |
-
|
| 67 |
-
def step(self, action: GovAction) -> GovObservation: # type: ignore[override]
|
| 68 |
-
"""
|
| 69 |
-
Execute a step in the environment.
|
| 70 |
-
|
| 71 |
-
Args:
|
| 72 |
-
action: GovAction containing the action to perform
|
| 73 |
-
|
| 74 |
-
Returns:
|
| 75 |
-
GovObservation with updated state and feedback
|
| 76 |
-
"""
|
| 77 |
-
self._state.step_count += 1
|
| 78 |
-
|
| 79 |
-
# Handle the action
|
| 80 |
-
observation = self._handle_action(action)
|
| 81 |
-
|
| 82 |
-
# Check if episode should end
|
| 83 |
-
observation.done = self._done or self._state.step_count >= 10
|
| 84 |
-
|
| 85 |
-
return observation
|
| 86 |
-
|
| 87 |
-
def _handle_action(self, action: GovAction) -> GovObservation:
|
| 88 |
-
"""Handle the specific action type."""
|
| 89 |
-
# For backward compatibility, if no action_type, treat as echo
|
| 90 |
-
if not action.action_type:
|
| 91 |
-
return GovObservation(
|
| 92 |
-
echoed_message=action.message,
|
| 93 |
-
message_length=len(action.message),
|
| 94 |
-
message=f"Echo: {action.message}",
|
| 95 |
-
current_stage=self._current_stage,
|
| 96 |
-
reward=min(len(action.message) * 0.1, 1.0),
|
| 97 |
-
done=False,
|
| 98 |
-
)
|
| 99 |
-
|
| 100 |
-
if action.action_type == "select_service":
|
| 101 |
-
return self._handle_select_service(action)
|
| 102 |
-
elif action.action_type == "list_required_documents":
|
| 103 |
-
return self._handle_list_required_documents(action)
|
| 104 |
-
elif action.action_type == "validate_documents":
|
| 105 |
-
return self._handle_validate_documents(action)
|
| 106 |
-
elif action.action_type == "suggest_corrections":
|
| 107 |
-
return self._handle_suggest_corrections(action)
|
| 108 |
-
elif action.action_type == "submit_application":
|
| 109 |
-
return self._handle_submit_application(action)
|
| 110 |
-
else:
|
| 111 |
-
return GovObservation(
|
| 112 |
-
message=f"Unknown action type: {action.action_type}",
|
| 113 |
-
current_stage=self._current_stage,
|
| 114 |
-
reward=-0.1,
|
| 115 |
-
done=self._done,
|
| 116 |
-
)
|
| 117 |
-
|
| 118 |
-
def _handle_select_service(self, action: GovAction) -> GovObservation:
|
| 119 |
-
"""Handle service selection action."""
|
| 120 |
-
if not action.service_type:
|
| 121 |
-
return GovObservation(
|
| 122 |
-
message="Please specify a service type to select.",
|
| 123 |
-
current_stage=self._current_stage,
|
| 124 |
-
reward=-0.05,
|
| 125 |
-
done=False,
|
| 126 |
-
)
|
| 127 |
-
|
| 128 |
-
service_type = action.service_type
|
| 129 |
-
available_services = ["passport_new", "passport_renewal", "pan_new", "aadhaar_update", "driving_license_new"]
|
| 130 |
-
|
| 131 |
-
if service_type not in available_services:
|
| 132 |
-
return GovObservation(
|
| 133 |
-
message=f"Unknown service type: {service_type}. Available: {available_services}",
|
| 134 |
-
current_stage=self._current_stage,
|
| 135 |
-
reward=-0.1,
|
| 136 |
-
done=False,
|
| 137 |
-
)
|
| 138 |
-
|
| 139 |
-
# Update state
|
| 140 |
-
self._service_type = service_type
|
| 141 |
-
self._required_documents = self._get_required_documents(service_type)
|
| 142 |
-
self._current_stage = "document_identification"
|
| 143 |
-
|
| 144 |
-
return GovObservation(
|
| 145 |
-
message=f"Selected service: {service_type}. {len(self._required_documents)} documents required.",
|
| 146 |
-
current_stage=self._current_stage,
|
| 147 |
-
service_type=self._service_type,
|
| 148 |
-
required_documents=self._required_documents,
|
| 149 |
-
reward=0.1,
|
| 150 |
-
done=False,
|
| 151 |
-
)
|
| 152 |
-
|
| 153 |
-
def _handle_list_required_documents(self, action: GovAction) -> GovObservation:
|
| 154 |
-
"""Handle listing required documents."""
|
| 155 |
-
if not self._service_type:
|
| 156 |
-
return GovObservation(
|
| 157 |
-
message="Please select a service first.",
|
| 158 |
-
current_stage=self._current_stage,
|
| 159 |
-
reward=-0.05,
|
| 160 |
-
done=False,
|
| 161 |
-
)
|
| 162 |
-
|
| 163 |
-
return GovObservation(
|
| 164 |
-
message=f"Required documents for {self._service_type}:",
|
| 165 |
-
current_stage=self._current_stage,
|
| 166 |
-
service_type=self._service_type,
|
| 167 |
-
required_documents=self._required_documents,
|
| 168 |
-
reward=0.05,
|
| 169 |
-
done=False,
|
| 170 |
-
)
|
| 171 |
-
|
| 172 |
-
def _handle_validate_documents(self, action: GovAction) -> GovObservation:
|
| 173 |
-
"""Handle document validation."""
|
| 174 |
-
if not action.documents:
|
| 175 |
-
return GovObservation(
|
| 176 |
-
message="Please provide documents to validate.",
|
| 177 |
-
current_stage=self._current_stage,
|
| 178 |
-
reward=-0.05,
|
| 179 |
-
done=False,
|
| 180 |
-
)
|
| 181 |
-
|
| 182 |
-
# Update submitted documents
|
| 183 |
-
self._submitted_documents = [doc.model_dump() for doc in action.documents]
|
| 184 |
-
|
| 185 |
-
# Perform validation
|
| 186 |
-
validation_results = self._validate_documents(action.documents)
|
| 187 |
-
self._validation_results = validation_results
|
| 188 |
-
|
| 189 |
-
# Update stage
|
| 190 |
-
self._current_stage = "validation"
|
| 191 |
-
|
| 192 |
-
# Generate message
|
| 193 |
-
if validation_results["is_complete"] and validation_results["is_valid"]:
|
| 194 |
-
message = "All documents are valid and complete. You can now submit the application."
|
| 195 |
-
self._current_stage = "submission"
|
| 196 |
-
elif validation_results["is_complete"] and not validation_results["is_valid"]:
|
| 197 |
-
message = f"Documents are complete but some are invalid. Found {len(validation_results['invalid_documents'])} invalid documents."
|
| 198 |
-
self._current_stage = "correction"
|
| 199 |
-
else:
|
| 200 |
-
message = f"Documents are incomplete. Missing {len(validation_results['missing_documents'])} required documents."
|
| 201 |
-
self._current_stage = "correction"
|
| 202 |
-
|
| 203 |
-
return GovObservation(
|
| 204 |
-
message=message,
|
| 205 |
-
current_stage=self._current_stage,
|
| 206 |
-
service_type=self._service_type,
|
| 207 |
-
submitted_documents=self._submitted_documents,
|
| 208 |
-
validation_results=validation_results,
|
| 209 |
-
reward=0.0,
|
| 210 |
-
done=False,
|
| 211 |
-
)
|
| 212 |
-
|
| 213 |
-
def _handle_suggest_corrections(self, action: GovAction) -> GovObservation:
|
| 214 |
-
"""Handle suggesting corrections."""
|
| 215 |
-
if not self._validation_results:
|
| 216 |
-
return GovObservation(
|
| 217 |
-
message="Please validate documents first.",
|
| 218 |
-
current_stage=self._current_stage,
|
| 219 |
-
reward=-0.05,
|
| 220 |
-
done=False,
|
| 221 |
-
)
|
| 222 |
-
|
| 223 |
-
corrections = self._generate_corrections()
|
| 224 |
-
self._correction_suggestions = corrections
|
| 225 |
-
|
| 226 |
-
if corrections:
|
| 227 |
-
message = f"Generated {len(corrections)} correction suggestions."
|
| 228 |
-
else:
|
| 229 |
-
message = "No corrections needed - all documents appear valid."
|
| 230 |
-
|
| 231 |
-
return GovObservation(
|
| 232 |
-
message=message,
|
| 233 |
-
current_stage=self._current_stage,
|
| 234 |
-
service_type=self._service_type,
|
| 235 |
-
submitted_documents=self._submitted_documents,
|
| 236 |
-
validation_results=self._validation_results,
|
| 237 |
-
correction_suggestions=corrections,
|
| 238 |
-
reward=0.0,
|
| 239 |
-
done=False,
|
| 240 |
-
)
|
| 241 |
-
|
| 242 |
-
def _handle_submit_application(self, action: GovAction) -> GovObservation:
|
| 243 |
-
"""Handle application submission."""
|
| 244 |
-
if not self._validation_results:
|
| 245 |
-
return GovObservation(
|
| 246 |
-
message="Please validate documents before submitting.",
|
| 247 |
-
current_stage=self._current_stage,
|
| 248 |
-
reward=-0.1,
|
| 249 |
-
done=False,
|
| 250 |
-
)
|
| 251 |
-
|
| 252 |
-
validation = self._validation_results
|
| 253 |
-
if not validation["is_complete"] or not validation["is_valid"]:
|
| 254 |
-
return GovObservation(
|
| 255 |
-
message="Cannot submit - documents are incomplete or invalid.",
|
| 256 |
-
current_stage=self._current_stage,
|
| 257 |
-
reward=-0.1,
|
| 258 |
-
done=False,
|
| 259 |
-
)
|
| 260 |
-
|
| 261 |
-
# Generate application ID and complete
|
| 262 |
-
application_id = f"APP-{str(uuid4())[:8].upper()}"
|
| 263 |
-
self._application_id = application_id
|
| 264 |
-
self._current_stage = "completed"
|
| 265 |
-
self._done = True
|
| 266 |
-
|
| 267 |
-
return GovObservation(
|
| 268 |
-
message=f"Application submitted successfully! ID: {application_id}",
|
| 269 |
-
current_stage=self._current_stage,
|
| 270 |
-
service_type=self._service_type,
|
| 271 |
-
application_id=application_id,
|
| 272 |
-
is_complete=True,
|
| 273 |
-
reward=0.5,
|
| 274 |
-
done=True,
|
| 275 |
-
)
|
| 276 |
-
|
| 277 |
-
def _get_required_documents(self, service_type: str) -> list[Dict[str, Any]]:
|
| 278 |
-
"""Get required documents for a service type."""
|
| 279 |
-
if service_type == "passport_new":
|
| 280 |
-
return [
|
| 281 |
-
{"type": "Proof of Address", "description": "Aadhaar/Voter ID/Utility bill", "mandatory": True},
|
| 282 |
-
{"type": "Proof of Date of Birth", "description": "Birth certificate/PAN/Aadhaar", "mandatory": True},
|
| 283 |
-
{"type": "Photograph", "description": "Recent passport-size photo", "mandatory": True}
|
| 284 |
-
]
|
| 285 |
-
elif service_type == "passport_renewal":
|
| 286 |
-
return [
|
| 287 |
-
{"type": "Old Passport", "description": "Original passport to renew", "mandatory": True},
|
| 288 |
-
{"type": "Proof of Address", "description": "Aadhaar/Voter ID/Utility bill", "mandatory": True},
|
| 289 |
-
{"type": "Photograph", "description": "Recent passport-size photo", "mandatory": True}
|
| 290 |
-
]
|
| 291 |
-
elif service_type == "pan_new":
|
| 292 |
-
return [
|
| 293 |
-
{"type": "Proof of Identity", "description": "Aadhaar/Voter ID/Driving license", "mandatory": True},
|
| 294 |
-
{"type": "Proof of Address", "description": "Aadhaar/Voter ID/Utility bill", "mandatory": True},
|
| 295 |
-
{"type": "Proof of Date of Birth", "description": "Birth certificate/PAN/Aadhaar", "mandatory": True}
|
| 296 |
-
]
|
| 297 |
-
elif service_type == "aadhaar_update":
|
| 298 |
-
return [
|
| 299 |
-
{"type": "Proof of Address", "description": "Utility bill/Bank statement/Rental agreement", "mandatory": True},
|
| 300 |
-
{"type": "Proof of Identity", "description": "PAN/Passport/Voter ID", "mandatory": True}
|
| 301 |
-
]
|
| 302 |
-
elif service_type == "driving_license_new":
|
| 303 |
-
return [
|
| 304 |
-
{"type": "Proof of Age", "description": "Birth certificate/School certificate", "mandatory": True},
|
| 305 |
-
{"type": "Proof of Address", "description": "Aadhaar/Voter ID/Utility bill", "mandatory": True},
|
| 306 |
-
{"type": "Application Form", "description": "Form 2 or Form 4", "mandatory": True}
|
| 307 |
-
]
|
| 308 |
-
return []
|
| 309 |
-
|
| 310 |
-
def _validate_documents(self, documents: list) -> Dict[str, Any]:
|
| 311 |
-
"""Validate submitted documents."""
|
| 312 |
-
result = {
|
| 313 |
-
"is_complete": False,
|
| 314 |
-
"is_valid": False,
|
| 315 |
-
"missing_documents": [],
|
| 316 |
-
"invalid_documents": [],
|
| 317 |
-
"valid_documents": []
|
| 318 |
-
}
|
| 319 |
-
|
| 320 |
-
required_types = {doc["type"] for doc in self._required_documents if doc["mandatory"]}
|
| 321 |
-
submitted_types = {doc.type for doc in documents}
|
| 322 |
-
|
| 323 |
-
# Check missing
|
| 324 |
-
result["missing_documents"] = list(required_types - submitted_types)
|
| 325 |
-
|
| 326 |
-
# Check invalid
|
| 327 |
-
for doc in documents:
|
| 328 |
-
is_valid = True
|
| 329 |
-
reason = ""
|
| 330 |
-
|
| 331 |
-
details_lower = doc.details.lower()
|
| 332 |
-
|
| 333 |
-
if "expired" in details_lower or "2023" in details_lower:
|
| 334 |
-
is_valid = False
|
| 335 |
-
reason = "Document appears to be expired"
|
| 336 |
-
elif doc.type == "Proof of Address" and "spouse" in details_lower:
|
| 337 |
-
is_valid = False
|
| 338 |
-
reason = "Must be in applicant's name"
|
| 339 |
-
elif doc.type == "Proof of Date of Birth" and "10th marksheet" in details_lower:
|
| 340 |
-
is_valid = False
|
| 341 |
-
reason = "Not sufficient as standalone DOB proof"
|
| 342 |
-
|
| 343 |
-
if is_valid:
|
| 344 |
-
result["valid_documents"].append(doc.type)
|
| 345 |
-
else:
|
| 346 |
-
result["invalid_documents"].append({"type": doc.type, "reason": reason})
|
| 347 |
-
|
| 348 |
-
result["is_complete"] = len(result["missing_documents"]) == 0
|
| 349 |
-
result["is_valid"] = len(result["invalid_documents"]) == 0
|
| 350 |
-
|
| 351 |
-
return result
|
| 352 |
-
|
| 353 |
-
def _generate_corrections(self) -> list[Dict[str, Any]]:
|
| 354 |
-
"""Generate correction suggestions."""
|
| 355 |
-
corrections = []
|
| 356 |
-
|
| 357 |
-
if not self._validation_results:
|
| 358 |
-
return corrections
|
| 359 |
-
|
| 360 |
-
# Handle missing documents
|
| 361 |
-
for missing in self._validation_results["missing_documents"]:
|
| 362 |
-
if missing == "Proof of Address":
|
| 363 |
-
corrections.append({
|
| 364 |
-
"issue_type": "missing",
|
| 365 |
-
"suggested_action": "Submit a valid address proof",
|
| 366 |
-
"alternative_documents": ["Aadhaar Card", "Voter ID", "Utility Bill"]
|
| 367 |
-
})
|
| 368 |
-
elif missing == "Proof of Date of Birth":
|
| 369 |
-
corrections.append({
|
| 370 |
-
"issue_type": "missing",
|
| 371 |
-
"suggested_action": "Submit a valid DOB proof",
|
| 372 |
-
"alternative_documents": ["Birth Certificate", "PAN Card", "Aadhaar Card"]
|
| 373 |
-
})
|
| 374 |
-
|
| 375 |
-
# Handle invalid documents
|
| 376 |
-
for invalid in self._validation_results["invalid_documents"]:
|
| 377 |
-
doc_type = invalid["type"]
|
| 378 |
-
reason = invalid["reason"]
|
| 379 |
-
|
| 380 |
-
if reason == "Document appears to be expired":
|
| 381 |
-
corrections.append({
|
| 382 |
-
"issue_type": "expired",
|
| 383 |
-
"current_document": doc_type,
|
| 384 |
-
"suggested_action": f"Replace expired {doc_type} with current version",
|
| 385 |
-
"alternative_documents": ["Updated version of same document"]
|
| 386 |
-
})
|
| 387 |
-
elif "applicant's name" in reason:
|
| 388 |
-
corrections.append({
|
| 389 |
-
"issue_type": "name_mismatch",
|
| 390 |
-
"current_document": doc_type,
|
| 391 |
-
"suggested_action": f"Submit {doc_type} in applicant's name",
|
| 392 |
-
"alternative_documents": ["Alternative address proof in applicant's name"]
|
| 393 |
-
})
|
| 394 |
-
|
| 395 |
-
return corrections
|
| 396 |
-
|
| 397 |
-
@property
|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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
server/gov_env_environment.py.backup
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 |
-
Gov 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 GovAction, GovObservation
|
| 21 |
-
except ImportError:
|
| 22 |
-
from models import GovAction, GovObservation
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
class GovEnvironment(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 = GovEnvironment()
|
| 34 |
-
>>> obs = env.reset()
|
| 35 |
-
>>> print(obs.echoed_message) # "Gov Env environment ready!"
|
| 36 |
-
>>>
|
| 37 |
-
>>> obs = env.step(GovAction(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 gov_env environment."""
|
| 50 |
-
self._state = State(episode_id=str(uuid4()), step_count=0)
|
| 51 |
-
self._reset_count = 0
|
| 52 |
-
|
| 53 |
-
def reset(self) -> GovObservation:
|
| 54 |
-
"""
|
| 55 |
-
Reset the environment.
|
| 56 |
-
|
| 57 |
-
Returns:
|
| 58 |
-
GovObservation with a ready message
|
| 59 |
-
"""
|
| 60 |
-
self._state = State(episode_id=str(uuid4()), step_count=0)
|
| 61 |
-
self._reset_count += 1
|
| 62 |
-
|
| 63 |
-
return GovObservation(
|
| 64 |
-
echoed_message="Gov Env environment ready!",
|
| 65 |
-
message_length=0,
|
| 66 |
-
done=False,
|
| 67 |
-
reward=0.0,
|
| 68 |
-
)
|
| 69 |
-
|
| 70 |
-
def step(self, action: GovAction) -> GovObservation: # type: ignore[override]
|
| 71 |
-
"""
|
| 72 |
-
Execute a step in the environment by echoing the message.
|
| 73 |
-
|
| 74 |
-
Args:
|
| 75 |
-
action: GovAction containing the message to echo
|
| 76 |
-
|
| 77 |
-
Returns:
|
| 78 |
-
GovObservation 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 GovObservation(
|
| 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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
server/requirements.txt
DELETED
|
@@ -1,6 +0,0 @@
|
|
| 1 |
-
openenv[core]>=0.2.0
|
| 2 |
-
fastapi>=0.115.0
|
| 3 |
-
uvicorn>=0.24.0
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|