38 lines
1.5 KiB
PHP
38 lines
1.5 KiB
PHP
<?php
|
|
// WEVIA Vision VL API — Qwen2.5-VL-32B via OpenRouter
|
|
header('Content-Type: application/json');
|
|
$_ws = [];
|
|
foreach(file('/etc/weval/secrets.env') as $l) {
|
|
$l = trim($l); if (!$l || $l[0]==='#') continue;
|
|
list($k,$v) = explode('=', $l, 2);
|
|
$_ws[trim($k)] = trim($v);
|
|
}
|
|
$key = $_ws['OPENROUTER_KEY'] ?? '';
|
|
if (!$key) { echo json_encode(['error'=>'no key']); exit; }
|
|
|
|
$imageUrl = $_POST['image_url'] ?? $_GET['image_url'] ?? '';
|
|
$prompt = $_POST['prompt'] ?? $_GET['prompt'] ?? 'Describe this image in detail';
|
|
|
|
if (!$imageUrl) { echo json_encode(['error'=>'no image_url']); exit; }
|
|
|
|
$msgs = [['role'=>'user','content'=>[
|
|
['type'=>'image_url','image_url'=>['url'=>$imageUrl]],
|
|
['type'=>'text','text'=>$prompt]
|
|
]]];
|
|
|
|
$ch = curl_init('https://openrouter.ai/api/v1/chat/completions');
|
|
curl_setopt_array($ch, [
|
|
CURLOPT_POST=>true, CURLOPT_RETURNTRANSFER=>true, CURLOPT_TIMEOUT=>30, CURLOPT_CONNECTTIMEOUT=>5,
|
|
CURLOPT_HTTPHEADER=>['Content-Type: application/json', 'Authorization: Bearer '.$key],
|
|
CURLOPT_POSTFIELDS=>json_encode(['model'=>'qwen/qwen2.5-vl-32b-instruct', 'messages'=>$msgs, 'max_tokens'=>1000, 'temperature'=>0.5])
|
|
]);
|
|
$r = curl_exec($ch); $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch);
|
|
|
|
if ($code == 200 && $r) {
|
|
$d = json_decode($r, true);
|
|
$text = $d['choices'][0]['message']['content'] ?? '';
|
|
echo json_encode(['response'=>$text, 'provider'=>'Qwen VL-32B', 'model'=>'qwen/qwen2.5-vl-32b-instruct']);
|
|
} else {
|
|
echo json_encode(['error'=>'API error', 'code'=>$code, 'raw'=>substr($r,0,200)]);
|
|
}
|