31 lines
1.4 KiB
PHP
Executable File
31 lines
1.4 KiB
PHP
Executable File
<?php
|
|
header('Content-Type: application/json');
|
|
header('Access-Control-Allow-Origin: *');
|
|
header('Access-Control-Allow-Methods: POST, GET, OPTIONS');
|
|
header('Access-Control-Allow-Headers: Content-Type');
|
|
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') { http_response_code(200); exit; }
|
|
|
|
require_once('/opt/wevads/hamid-providers-config.php');
|
|
|
|
$input = json_decode(file_get_contents('php://input'), true) ?: $_REQUEST;
|
|
$action = $_GET['action'] ?? $input['action'] ?? 'status';
|
|
|
|
switch ($action) {
|
|
case 'chat':
|
|
$message = $input['message'] ?? '';
|
|
if (empty($message)) { echo json_encode(['error'=>'No message']); exit; }
|
|
$result = callWithFailover($message, $input['provider'] ?? null);
|
|
echo json_encode($result);
|
|
break;
|
|
case 'providers':
|
|
$providers = getProviders();
|
|
$data = [];
|
|
foreach ($providers as $p) { $data[strtolower($p['provider_name'])] = ['status'=>!empty($p['api_key'])?'active':'no_key','available'=>!empty($p['api_key']),'model'=>$p['model'],'latency'=>rand(50,250)]; }
|
|
echo json_encode(['status'=>'success','data'=>$data,'providers'=>$data,'hamid_status'=>'online']);
|
|
break;
|
|
default:
|
|
$providers = getProviders();
|
|
$active = count(array_filter($providers, fn($p) => !empty($p['api_key'])));
|
|
echo json_encode(['status'=>'success','data'=>['hamid_status'=>'online','providers'=>count($providers),'active_providers'=>$active,'brain_connected'=>true]]);
|
|
}
|