Files
html/api/opus-arch-gpu-grid-prod.php
opus 6931d33a7d
Some checks failed
WEVAL NonReg / nonreg (push) Has been cancelled
V39 architect final: 7 remaining R&D caps wired (4/9/10/11/13/15/16) + doctrines 94-100
2026-04-17 19:26:56 +02:00

49 lines
2.4 KiB
PHP

<?php
// opus-arch-gpu-grid-prod.php - Cap 10 (Doctrine 96)
header('Content-Type: application/json');
$action = $_GET['action'] ?? 'status';
$providers = [
'kaggle'=>['url'=>'https://www.kaggle.com/api/v1', 'key_env'=>'KAGGLE_API_KEY', 'free_tier'=>'30h/week T4'],
'hf-space'=>['url'=>'https://huggingface.co/api', 'key_env'=>'HF_TOKEN', 'free_tier'=>'CPU basic'],
'colab'=>['url'=>'manual', 'key_env'=>'COLAB_NOTEBOOK_URL', 'free_tier'=>'T4 12h'],
'cf-workers-ai'=>['url'=>'https://api.cloudflare.com/client/v4', 'key_env'=>'CF_API_TOKEN', 'free_tier'=>'10K req/day'],
'sovereign-local'=>['url'=>'http://127.0.0.1:4000', 'key_env'=>'', 'free_tier'=>'13 providers cascade'],
];
if ($action === 'status') {
$status = [];
foreach ($providers as $name => $p) {
if ($p['url'] === 'manual') { $status[$name] = 'manual'; continue; }
$secrets = @file('/etc/weval/secrets.env');
$has_key = empty($p['key_env']) ? true : false;
foreach ($secrets ?? [] as $line) {
if (strpos($line, $p['key_env'] . '=') === 0) { $has_key = true; break; }
}
$status[$name] = $has_key ? 'configured' : 'missing_key';
}
echo json_encode(['ok'=>true, 'providers'=>$providers, 'status'=>$status]); exit;
}
if ($action === 'shard') {
$prompt = $_POST['prompt'] ?? '';
$chunks = (int)($_POST['chunks'] ?? 3);
if (!$prompt) { echo json_encode(['ok'=>false,'error'=>'prompt required']); exit; }
$chunk_size = (int)(strlen($prompt) / $chunks) + 1;
$pieces = [];
for ($i = 0; $i < $chunks; $i++) {
$pieces[] = substr($prompt, $i * $chunk_size, $chunk_size);
}
// Sharding implementation: cascade through sovereign (13 providers existing)
$result_pieces = [];
foreach ($pieces as $idx => $p) {
$payload = json_encode(['message'=>$p, 'max_tokens'=>500]);
$ch = curl_init('http://127.0.0.1:4000/v1/chat/completions');
curl_setopt_array($ch, [CURLOPT_POST=>true, CURLOPT_POSTFIELDS=>$payload, CURLOPT_RETURNTRANSFER=>true, CURLOPT_TIMEOUT=>15, CURLOPT_HTTPHEADER=>['Content-Type: application/json']]);
$o = curl_exec($ch);
curl_close($ch);
$result_pieces[] = ['idx'=>$idx, 'len'=>strlen($p), 'response_len'=>strlen($o ?? '')];
}
echo json_encode(['ok'=>true, 'chunks'=>count($pieces), 'results'=>$result_pieces]); exit;
}
echo json_encode(['ok'=>false, 'actions'=>['status','shard']]);