40 lines
1.1 KiB
PHP
40 lines
1.1 KiB
PHP
<?php
|
|
header("Content-Type: application/json");
|
|
|
|
// Read key
|
|
$env = @file_get_contents("/etc/weval/secrets.env");
|
|
preg_match("/GROQ_KEY=(.+)/", $env, $m);
|
|
$key = trim($m[1] ?? "");
|
|
|
|
$prompt = $_GET["q"] ?? "bonjour en 1 mot";
|
|
$system = $_GET["s"] ?? "Tu es WEVIA.";
|
|
|
|
$data = json_encode(["model" => "llama-3.3-70b-versatile", "messages" => [
|
|
["role" => "system", "content" => $system],
|
|
["role" => "user", "content" => $prompt]
|
|
], "max_tokens" => 500]);
|
|
|
|
$ch = curl_init("https://api.groq.com/openai/v1/chat/completions");
|
|
curl_setopt_array($ch, [
|
|
CURLOPT_RETURNTRANSFER => true,
|
|
CURLOPT_POST => true,
|
|
CURLOPT_POSTFIELDS => $data,
|
|
CURLOPT_HTTPHEADER => ["Content-Type: application/json", "Authorization: Bearer $key"],
|
|
CURLOPT_TIMEOUT => 20,
|
|
CURLOPT_SSL_VERIFYPEER => false
|
|
]);
|
|
$r = curl_exec($ch);
|
|
$err = curl_error($ch);
|
|
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
|
curl_close($ch);
|
|
|
|
$d = @json_decode($r, true);
|
|
$content = $d["choices"][0]["message"]["content"] ?? null;
|
|
|
|
echo json_encode([
|
|
"ok" => !!$content,
|
|
"content" => $content ?? "error: $err (HTTP $code)",
|
|
"resp_len" => strlen($r),
|
|
"key_len" => strlen($key)
|
|
]);
|