Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /rubelw_OSSS /src /OSSS /ai /api /external.py
| """ | |
| External API contracts for OSSS. | |
| These APIs form the stable interface that external consumers depend on. | |
| Key points about this module: | |
| - It defines *contracts* (interfaces / abstract-ish base classes), not implementations. | |
| - External callers should code against these contracts, not internal orchestrator classes. | |
| - Any breaking change to these signatures or semantics requires: | |
| 1) a migration path | |
| 2) an API version bump | |
| - Concrete implementations live elsewhere (e.g., LangGraphOrchestrationAPI). | |
| """ | |
| from __future__ import annotations | |
| # --------------------------------------------------------------------------- | |
| # Standard library imports | |
| # --------------------------------------------------------------------------- | |
| import importlib | |
| import warnings | |
| from typing import List, Dict, Any, Optional, Type | |
| # --------------------------------------------------------------------------- | |
| # Local package imports (API infrastructure) | |
| # --------------------------------------------------------------------------- | |
| from .base import BaseAPI | |
| from .decorators import ensure_initialized | |
| # --------------------------------------------------------------------------- | |
| # Local package imports (request/response models) | |
| # --------------------------------------------------------------------------- | |
| from .models import ( | |
| WorkflowRequest, | |
| WorkflowResponse, | |
| StatusResponse, | |
| CompletionRequest, | |
| CompletionResponse, | |
| LLMProviderInfo, | |
| ) | |
| class OrchestrationAPI(BaseAPI): | |
| """ | |
| Public orchestration API - STABLE INTERFACE. | |
| """ | |
| def api_name(self) -> str: | |
| return "Orchestration API" | |
| def api_version(self) -> str: | |
| return "1.0.0" | |
| async def execute_workflow(self, request: WorkflowRequest) -> WorkflowResponse: | |
| raise NotImplementedError("Subclasses must implement execute_workflow") | |
| async def get_status(self, workflow_id: str) -> StatusResponse: | |
| raise NotImplementedError("Subclasses must implement get_status") | |
| async def cancel_workflow(self, workflow_id: str) -> bool: | |
| raise NotImplementedError("Subclasses must implement cancel_workflow") | |
| def get_workflow_history(self, limit: int = 10) -> List[Dict[str, Any]]: | |
| raise NotImplementedError("Subclasses must implement get_workflow_history") | |
| async def get_workflow_history_from_database( | |
| self, | |
| limit: int = 10, | |
| offset: int = 0, | |
| ) -> List[Dict[str, Any]]: | |
| raise NotImplementedError( | |
| "Subclasses must implement get_workflow_history_from_database" | |
| ) | |
| async def get_status_by_correlation_id(self, correlation_id: str) -> StatusResponse: | |
| raise NotImplementedError( | |
| "Subclasses must implement get_status_by_correlation_id" | |
| ) | |
| class LLMGatewayAPI(BaseAPI): | |
| """ | |
| LLM Gateway API - Future service extraction boundary. | |
| ⚠️ IMPORTANT: THIS API IS NOT YET IMPLEMENTED ⚠️ | |
| """ | |
| def api_name(self) -> str: | |
| return "LLM Gateway API" | |
| def api_version(self) -> str: | |
| return "1.0.0" | |
| async def complete(self, request: CompletionRequest) -> CompletionResponse: | |
| warnings.warn( | |
| "LLMGatewayAPI.complete() is not implemented. This is a placeholder for future LLM gateway service. " | |
| "Use OSSS.ai.llm.OpenAIChatLLM or similar classes for current LLM functionality.", | |
| UserWarning, | |
| stacklevel=2, | |
| ) | |
| raise NotImplementedError( | |
| "LLMGatewayAPI.complete() is not yet implemented - this is a future placeholder" | |
| ) | |
| async def get_providers(self) -> List[LLMProviderInfo]: | |
| warnings.warn( | |
| "LLMGatewayAPI.get_providers() is not implemented. This is a placeholder for future LLM gateway service.", | |
| UserWarning, | |
| stacklevel=2, | |
| ) | |
| raise NotImplementedError( | |
| "LLMGatewayAPI.get_providers() is not yet implemented - this is a future placeholder" | |
| ) | |
| async def estimate_cost(self, request: CompletionRequest) -> Dict[str, float]: | |
| warnings.warn( | |
| "LLMGatewayAPI.estimate_cost() is not implemented. This is a placeholder for future LLM gateway service.", | |
| UserWarning, | |
| stacklevel=2, | |
| ) | |
| raise NotImplementedError( | |
| "LLMGatewayAPI.estimate_cost() is not yet implemented - this is a future placeholder" | |
| ) | |
| # --------------------------------------------------------------------------- | |
| # Concrete orchestration implementation (best-effort import, NO import-time crash) | |
| # --------------------------------------------------------------------------- | |
| # If your concrete implementation moves, add its module path here. | |
| # Keep this list short and explicit. | |
| _LANGGRAPH_IMPL_CANDIDATES = [ | |
| # Actual current implementation location | |
| "OSSS.ai.api.orchestration_api", # defines LangGraphOrchestrationAPI | |
| # Other possible/legacy locations (keep if you want) | |
| "OSSS.ai.api.langgraph", | |
| "OSSS.ai.api.langgraph_api", | |
| "OSSS.ai.api.orchestration_langgraph", | |
| "OSSS.ai.api.impl.langgraph_orchestration", | |
| "OSSS.ai.api.external_impl", | |
| "OSSS.ai.api.langgraph_orchestration_api", | |
| ] | |
| def _resolve_langgraph_api_class() -> Type[Any]: | |
| """ | |
| Try to locate LangGraphOrchestrationAPI without crashing module import. | |
| """ | |
| for module_path in _LANGGRAPH_IMPL_CANDIDATES: | |
| try: | |
| mod = importlib.import_module(module_path) | |
| except ModuleNotFoundError: | |
| continue | |
| cls = getattr(mod, "LangGraphOrchestrationAPI", None) | |
| if cls is not None: | |
| return cls | |
| raise ImportError( | |
| "LangGraphOrchestrationAPI could not be located. " | |
| "Update OSSS.ai.api.external._LANGGRAPH_IMPL_CANDIDATES to include the module " | |
| "that defines `class LangGraphOrchestrationAPI`." | |
| ) | |
| class LangGraphOrchestrationAPI: # type: ignore[misc] | |
| """ | |
| Proxy symbol to preserve the existing import style: | |
| from OSSS.ai.api.external import LangGraphOrchestrationAPI | |
| Resolution is deferred so external.py never hard-crashes app startup. | |
| """ | |
| def __new__(cls, *args: Any, **kwargs: Any): | |
| real_cls = _resolve_langgraph_api_class() | |
| return real_cls(*args, **kwargs) | |
| __all__ = [ | |
| "OrchestrationAPI", | |
| "LLMGatewayAPI", | |
| "LangGraphOrchestrationAPI", | |
| ] | |
Xet Storage Details
- Size:
- 6.6 kB
- Xet hash:
- 88aca28324eeb68ef7660859e5697fcc738188ab88bb34eb1b3f37e85e760590
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.