Spaces:
Running
Running
Commit
·
4c3e379
1
Parent(s):
cd6c13a
Rename start_time parameter to time_to_start for consistency in API validation
Browse files- api_validator.py +16 -17
api_validator.py
CHANGED
@@ -25,7 +25,7 @@ def validate_api_call(
|
|
25 |
additional_params,
|
26 |
schedule_interval_minutes,
|
27 |
stop_after_hours,
|
28 |
-
|
29 |
):
|
30 |
"""
|
31 |
TOOL: Validate and store API configuration for monitoring.
|
@@ -51,7 +51,7 @@ def validate_api_call(
|
|
51 |
- additional_params: Optional JSON string for complex parameters
|
52 |
- schedule_interval_minutes: Minutes between calls
|
53 |
- stop_after_hours: Hours after which to stop (max 168 = 1 week)
|
54 |
-
-
|
55 |
|
56 |
Input Examples:
|
57 |
|
@@ -67,7 +67,7 @@ def validate_api_call(
|
|
67 |
additional_params: "{}"
|
68 |
schedule_interval_minutes: 30
|
69 |
stop_after_hours: 24
|
70 |
-
|
71 |
|
72 |
2. API with complex parameters:
|
73 |
mcp_api_key: "your_mcp_key_here"
|
@@ -81,7 +81,7 @@ def validate_api_call(
|
|
81 |
additional_params: '{"severity": ["severe", "extreme"], "types": ["tornado", "hurricane"]}'
|
82 |
schedule_interval_minutes: 15
|
83 |
stop_after_hours: 48
|
84 |
-
|
85 |
|
86 |
3. GitHub API monitoring:
|
87 |
mcp_api_key: "your_mcp_key_here"
|
@@ -95,7 +95,7 @@ def validate_api_call(
|
|
95 |
additional_params: "{}"
|
96 |
schedule_interval_minutes: 60
|
97 |
stop_after_hours: 168
|
98 |
-
|
99 |
|
100 |
Returns:
|
101 |
- Dictionary with success status, config_id (needed for setup_scheduler), message, and sample_response
|
@@ -164,13 +164,13 @@ def validate_api_call(
|
|
164 |
"config_id": None,
|
165 |
}
|
166 |
|
167 |
-
# Validate
|
168 |
-
if
|
169 |
try:
|
170 |
-
|
171 |
-
|
172 |
)
|
173 |
-
if
|
174 |
return {
|
175 |
"success": False,
|
176 |
"message": "Start time cannot be in the past",
|
@@ -183,7 +183,7 @@ def validate_api_call(
|
|
183 |
"config_id": None,
|
184 |
}
|
185 |
else:
|
186 |
-
|
187 |
|
188 |
# Test the API call
|
189 |
result = apiCall.api_call(
|
@@ -216,7 +216,6 @@ def validate_api_call(
|
|
216 |
"additional_params": additional_params,
|
217 |
"schedule_interval_minutes": schedule_interval_minutes,
|
218 |
"stop_after_hours": stop_after_hours,
|
219 |
-
"start_time": start_time,
|
220 |
}
|
221 |
|
222 |
# Generate unique config ID
|
@@ -227,14 +226,14 @@ def validate_api_call(
|
|
227 |
|
228 |
# Calculate timestamps
|
229 |
created_at = datetime.now()
|
230 |
-
stop_at =
|
231 |
|
232 |
# Add metadata to config
|
233 |
config_data.update(
|
234 |
{
|
235 |
"config_id": config_id,
|
236 |
"created_at": created_at.isoformat(),
|
237 |
-
"start_at":
|
238 |
"stop_at": stop_at.isoformat(),
|
239 |
# @JamezyKim This will be used to track the status of whether the api is confirmed or not
|
240 |
"is_validated": False,
|
@@ -290,7 +289,7 @@ def validate_api_call(
|
|
290 |
False,
|
291 |
False,
|
292 |
schedule_interval_minutes,
|
293 |
-
|
294 |
created_at,
|
295 |
None,
|
296 |
),
|
@@ -315,7 +314,7 @@ def validate_api_call(
|
|
315 |
if result.startswith("{") or result.startswith("[")
|
316 |
else result
|
317 |
),
|
318 |
-
"start_at":
|
319 |
"stop_at": stop_at.isoformat(),
|
320 |
"schedule_interval_minutes": schedule_interval_minutes,
|
321 |
}
|
@@ -401,6 +400,6 @@ if __name__ == "__main__":
|
|
401 |
additional_params="{}",
|
402 |
schedule_interval_minutes=20,
|
403 |
stop_after_hours=24,
|
404 |
-
|
405 |
)
|
406 |
print(response)
|
|
|
25 |
additional_params,
|
26 |
schedule_interval_minutes,
|
27 |
stop_after_hours,
|
28 |
+
time_to_start,
|
29 |
):
|
30 |
"""
|
31 |
TOOL: Validate and store API configuration for monitoring.
|
|
|
51 |
- additional_params: Optional JSON string for complex parameters
|
52 |
- schedule_interval_minutes: Minutes between calls
|
53 |
- stop_after_hours: Hours after which to stop (max 168 = 1 week)
|
54 |
+
- time_to_start: When to start the monitoring (datetime string or None for immediate)
|
55 |
|
56 |
Input Examples:
|
57 |
|
|
|
67 |
additional_params: "{}"
|
68 |
schedule_interval_minutes: 30
|
69 |
stop_after_hours: 24
|
70 |
+
time_to_start: ""
|
71 |
|
72 |
2. API with complex parameters:
|
73 |
mcp_api_key: "your_mcp_key_here"
|
|
|
81 |
additional_params: '{"severity": ["severe", "extreme"], "types": ["tornado", "hurricane"]}'
|
82 |
schedule_interval_minutes: 15
|
83 |
stop_after_hours: 48
|
84 |
+
time_to_start: "2024-06-15 09:00:00"
|
85 |
|
86 |
3. GitHub API monitoring:
|
87 |
mcp_api_key: "your_mcp_key_here"
|
|
|
95 |
additional_params: "{}"
|
96 |
schedule_interval_minutes: 60
|
97 |
stop_after_hours: 168
|
98 |
+
time_to_start: ""
|
99 |
|
100 |
Returns:
|
101 |
- Dictionary with success status, config_id (needed for setup_scheduler), message, and sample_response
|
|
|
164 |
"config_id": None,
|
165 |
}
|
166 |
|
167 |
+
# Validate time_to_start if provided
|
168 |
+
if time_to_start:
|
169 |
try:
|
170 |
+
parsed_start_time = datetime.fromisoformat(
|
171 |
+
time_to_start.replace("Z", "+00:00")
|
172 |
)
|
173 |
+
if parsed_start_time < datetime.now():
|
174 |
return {
|
175 |
"success": False,
|
176 |
"message": "Start time cannot be in the past",
|
|
|
183 |
"config_id": None,
|
184 |
}
|
185 |
else:
|
186 |
+
parsed_start_time = datetime.now()
|
187 |
|
188 |
# Test the API call
|
189 |
result = apiCall.api_call(
|
|
|
216 |
"additional_params": additional_params,
|
217 |
"schedule_interval_minutes": schedule_interval_minutes,
|
218 |
"stop_after_hours": stop_after_hours,
|
|
|
219 |
}
|
220 |
|
221 |
# Generate unique config ID
|
|
|
226 |
|
227 |
# Calculate timestamps
|
228 |
created_at = datetime.now()
|
229 |
+
stop_at = parsed_start_time + timedelta(hours=stop_after_hours)
|
230 |
|
231 |
# Add metadata to config
|
232 |
config_data.update(
|
233 |
{
|
234 |
"config_id": config_id,
|
235 |
"created_at": created_at.isoformat(),
|
236 |
+
"start_at": parsed_start_time.isoformat(),
|
237 |
"stop_at": stop_at.isoformat(),
|
238 |
# @JamezyKim This will be used to track the status of whether the api is confirmed or not
|
239 |
"is_validated": False,
|
|
|
289 |
False,
|
290 |
False,
|
291 |
schedule_interval_minutes,
|
292 |
+
parsed_start_time,
|
293 |
created_at,
|
294 |
None,
|
295 |
),
|
|
|
314 |
if result.startswith("{") or result.startswith("[")
|
315 |
else result
|
316 |
),
|
317 |
+
"start_at": parsed_start_time.isoformat(),
|
318 |
"stop_at": stop_at.isoformat(),
|
319 |
"schedule_interval_minutes": schedule_interval_minutes,
|
320 |
}
|
|
|
400 |
additional_params="{}",
|
401 |
schedule_interval_minutes=20,
|
402 |
stop_after_hours=24,
|
403 |
+
time_to_start="",
|
404 |
)
|
405 |
print(response)
|