added example for DAIAPI communication

This commit is contained in:
2026-06-12 16:10:07 +02:00
parent 3849e0572c
commit 3c6344e94f

View File

@ -36,9 +36,51 @@ Implementovať klienta pre DAIAPI a vytvoriť generátor promptov, ktorý na zá
Žiadne.
## API a dátové štruktúry
DAIAPI typicky očakáva:
- URL: `http://webwizard.test:port/v1/chat/completions` (podľa lokálneho nastavenia).
- Formát: JSON (messages, temperature, atď.).
DAIAPI je proprietarne API, ktore sa da pouzivat volanim na VPN adresu 10.2.8.1 a port 9001, prakticka implementacia v PHP:
```php
function daiAPIrun(string $prompt): ?string
{
$url = "http://192.168.122.10:9001/run";
$payload = json_encode([
"prompt" => $prompt
]);
if ($payload === false) {
return null;
}
$ch = curl_init($url);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"Content-Length: " . strlen($payload)
],
CURLOPT_POSTFIELDS => $payload,
CURLOPT_TIMEOUT => 60,
]);
$response = curl_exec($ch);
if ($response === false) {
curl_close($ch);
return null;
}
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($httpCode !== 200) {
return null;
}
$data = json_decode($response, true);
if (!is_array($data)) {
return null;
}
// očakávame: { "success": true, "answer": "...", ... }
if (empty($data["success"]) || !isset($data["answer"])) {
return null;
}
return $data["answer"];
}
```
## Frontend požiadavky
Nerelevantné.