cryogenic22 commited on
Commit
070c020
·
verified ·
1 Parent(s): 71c5820

Create core/base.py

Browse files
Files changed (1) hide show
  1. core/base.py +60 -0
core/base.py ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from abc import ABC, abstractmethod
2
+ from typing import Dict, Any, Optional
3
+ from pydantic import BaseModel
4
+ import logging
5
+ from datetime import datetime
6
+
7
+ class LatticeComponent(ABC):
8
+ """Base class for all Lattice components"""
9
+
10
+ def __init__(self, config: Optional[Dict[str, Any]] = None):
11
+ self.config = config or {}
12
+ self.logger = logging.getLogger(f"lattice.{self.__class__.__name__}")
13
+ self._initialized = False
14
+
15
+ @abstractmethod
16
+ async def initialize(self) -> None:
17
+ """Initialize the component"""
18
+ self._initialized = True
19
+
20
+ @abstractmethod
21
+ async def validate_config(self) -> bool:
22
+ """Validate component configuration"""
23
+ pass
24
+
25
+ def ensure_initialized(self):
26
+ """Ensure component is initialized"""
27
+ if not self._initialized:
28
+ raise RuntimeError(f"{self.__class__.__name__} not initialized")
29
+
30
+ class LatticeError(Exception):
31
+ """Base class for Lattice errors"""
32
+ pass
33
+
34
+ class ConfigurationError(LatticeError):
35
+ """Configuration related errors"""
36
+ pass
37
+
38
+ class ExecutionError(LatticeError):
39
+ """Execution related errors"""
40
+ pass
41
+
42
+ class BaseRequest(BaseModel):
43
+ """Base class for all requests"""
44
+ request_id: Optional[str]
45
+ timestamp: Optional[datetime]
46
+
47
+ class BaseResponse(BaseModel):
48
+ """Base class for all responses"""
49
+ request_id: Optional[str]
50
+ timestamp: datetime
51
+ status: str
52
+ error: Optional[str]
53
+
54
+ class ComponentMetadata(BaseModel):
55
+ """Component metadata"""
56
+ name: str
57
+ version: str
58
+ description: Optional[str]
59
+ capabilities: Dict[str, Any]
60
+ dependencies: Dict[str, str]