-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmodels.py
More file actions
129 lines (102 loc) · 3.37 KB
/
models.py
File metadata and controls
129 lines (102 loc) · 3.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/usr/bin/env python3
"""
Pydantic models for GNN API request/response validation.
These models define the API contract — request shapes and response schemas.
"""
from datetime import datetime
from enum import Enum
from typing import Any, Dict, List, Optional
try:
from pydantic import BaseModel, Field
except ImportError as e:
raise ImportError(
"pydantic is required for the GNN API module. "
"Install with: uv sync --extra api"
) from e
class JobStatus(str, Enum):
"""Pipeline job execution status."""
PENDING = "pending"
RUNNING = "running"
COMPLETED = "completed"
FAILED = "failed"
CANCELLED = "cancelled"
class ProcessRequest(BaseModel):
"""Request to process GNN files through pipeline steps."""
target_dir: str = Field(
default="input/gnn_files",
description="Directory containing GNN files to process"
)
steps: Optional[List[int]] = Field(
default=None,
description="Specific pipeline steps to run (e.g., [3,5,8]). None = all steps."
)
skip_steps: Optional[List[int]] = Field(
default=None,
description="Pipeline steps to skip"
)
verbose: bool = Field(
default=False,
description="Enable verbose logging output"
)
strict: bool = Field(
default=False,
description="Treat warnings as errors"
)
model_config = {"json_schema_extra": {
"example": {
"target_dir": "input/gnn_files",
"steps": [3, 5, 6, 8],
"verbose": True
}
}}
class ToolRequest(BaseModel):
"""Request to invoke a single pipeline step/tool."""
target_dir: str = Field(
default="input/gnn_files",
description="Directory containing GNN files"
)
verbose: bool = Field(default=False)
kwargs: Dict[str, Any] = Field(
default_factory=dict,
description="Step-specific parameters"
)
class JobResponse(BaseModel):
"""Response containing job ID and initial status."""
job_id: str = Field(description="Unique job identifier")
status: JobStatus = Field(description="Current job status")
created_at: datetime = Field(description="Job creation timestamp")
steps_requested: Optional[List[int]] = Field(default=None)
message: str = Field(default="Job queued for execution")
class JobStatusResponse(BaseModel):
"""Detailed job status response."""
job_id: str
status: JobStatus
created_at: datetime
started_at: Optional[datetime] = None
completed_at: Optional[datetime] = None
progress_step: Optional[int] = Field(
default=None,
description="Currently executing step number"
)
steps_completed: List[int] = Field(default_factory=list)
steps_failed: List[int] = Field(default_factory=list)
exit_code: Optional[int] = None
error_message: Optional[str] = None
output_dir: Optional[str] = None
class ToolInfo(BaseModel):
"""Information about an available pipeline tool/step."""
step_number: int
name: str
description: str
script: str
class ToolsResponse(BaseModel):
"""List of available pipeline tools."""
tools: List[ToolInfo]
total: int
class HealthResponse(BaseModel):
"""API health check response."""
status: str = "healthy"
version: str
pipeline_steps: int
active_jobs: int
timestamp: datetime = Field(default_factory=datetime.now)