Files
html/api/notebooks/wevia-colab-gpu.py
2026-04-12 22:57:03 +02:00

43 lines
1.7 KiB
Python

<?php
$secrets = [];
foreach (file('/etc/weval/secrets.env', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) as $line) {
if (empty(trim($line)) || $line[0] === '#') continue;
$pos = strpos($line, '=');
if ($pos) $secrets[trim(substr($line, 0, $pos))] = trim(substr($line, $pos + 1), " \t\"'");
}
$key = $secrets['GEMINI_KEY'];
$payload = json_encode([
'contents' => [['parts' => [['text' => 'Dis "WEVIA est souverain" en une phrase']]]],
'generationConfig' => ['maxOutputTokens' => 100, 'temperature' => 0.3],
]);
$start = microtime(true);
$ch = curl_init("https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent?key=$key");
curl_setopt_array($ch, [
CURLOPT_POST => true, CURLOPT_POSTFIELDS => $payload,
CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 15,
]);
$r = curl_exec($ch);
$lat = round((microtime(true) - $start) * 1000);
curl_close($ch);
$d = json_decode($r, true);
$text = $d['candidates'][0]['content']['parts'][0]['text'] ?? 'EMPTY';
echo "GEMINI 2.5-flash: ${lat}ms → $text\n";
// Also test gemini-3-flash
$ch2 = curl_init("https://generativelanguage.googleapis.com/v1beta/models/gemini-3-flash-preview:generateContent?key=$key");
curl_setopt_array($ch2, [
CURLOPT_POST => true, CURLOPT_POSTFIELDS => $payload,
CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 15,
]);
$start2 = microtime(true);
$r2 = curl_exec($ch2);
$lat2 = round((microtime(true) - $start2) * 1000);
curl_close($ch2);
$d2 = json_decode($r2, true);
$text2 = $d2['candidates'][0]['content']['parts'][0]['text'] ?? 'EMPTY';
echo "GEMINI 3-flash: ${lat2}ms → $text2\n";