-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathai_config_test_connection.php
More file actions
46 lines (41 loc) · 1.32 KB
/
Copy pathai_config_test_connection.php
File metadata and controls
46 lines (41 loc) · 1.32 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
<?php
require 'session_config.php';
require 'dbcon.php';
require_once __DIR__ . '/includes/ai_settings.php';
require_once __DIR__ . '/includes/llm_provider.php';
require_once __DIR__ . '/includes/ai_configs.php';
header('Content-Type: application/json');
header('Cache-Control: no-store');
if (!isset($_SESSION['username']) || ($_SESSION['role'] ?? '') !== 'admin') {
http_response_code(403);
echo json_encode(['ok' => false, 'message' => 'Admin role required.']);
exit;
}
$configId = isset($_GET['config_id']) ? (int)$_GET['config_id'] : 0;
if ($configId <= 0) {
http_response_code(400);
echo json_encode(['ok' => false, 'message' => 'Missing config_id.']);
exit;
}
try {
$res = ai_configs_test_connection($con, $configId);
} catch (Throwable $e) {
http_response_code(500);
echo json_encode(['ok' => false, 'message' => 'Test error: ' . $e->getMessage()]);
exit;
}
if (!empty($res['ok'])) {
echo json_encode([
'ok' => true,
'used_key' => $res['used_key'] ?? 'primary',
'model_count' => $res['model_count'] ?? null,
'http_status' => $res['http_status'] ?? 200,
]);
exit;
}
echo json_encode([
'ok' => false,
'used_key' => $res['used_key'] ?? '',
'http_status' => $res['http_status'] ?? 0,
'message' => $res['error'] ?? 'Unknown error',
]);