35 lines
1.3 KiB
PHP
35 lines
1.3 KiB
PHP
<?php
|
|
header("Content-Type: application/json");
|
|
error_reporting(E_ALL);
|
|
ini_set("display_errors","0");
|
|
ini_set("log_errors","1");
|
|
ini_set("error_log","/tmp/wevia-chat-test.log");
|
|
|
|
$input = json_decode(file_get_contents("php://input"), true);
|
|
$msg = $input["message"] ?? $_POST["message"] ?? "";
|
|
if (!$msg) die(json_encode(["error"=>"no message"]));
|
|
|
|
// Try Groq directly (simplest provider)
|
|
$secrets = file_get_contents("/etc/weval/secrets.env");
|
|
preg_match("/GROQ[_A-Z]*=(.+)/i", $secrets, $m);
|
|
$key = trim($m[1] ?? "");
|
|
|
|
$ch = curl_init("https://api.groq.com/openai/v1/chat/completions");
|
|
curl_setopt_array($ch, [
|
|
CURLOPT_RETURNTRANSFER => true,
|
|
CURLOPT_POST => true,
|
|
CURLOPT_HTTPHEADER => ["Authorization: Bearer $key","Content-Type: application/json"],
|
|
CURLOPT_POSTFIELDS => json_encode(["model"=>"llama-3.3-70b-versatile","messages"=>[["role"=>"user","content"=>$msg]],"max_tokens"=>200]),
|
|
CURLOPT_TIMEOUT => 10,
|
|
]);
|
|
$r = curl_exec($ch);
|
|
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
|
// curl_close deprecated in PHP 8.5
|
|
|
|
if ($code == 200) {
|
|
$d = json_decode($r, true);
|
|
$text = $d["choices"][0]["message"]["content"] ?? "no response";
|
|
echo json_encode(["response"=>$text,"provider"=>"groq","status"=>"ok"]);
|
|
} else {
|
|
echo json_encode(["error"=>"provider failed","http"=>$code,"raw"=>substr($r,0,100)]);
|
|
} |