- StoreForge API: e-commerce site generator via WEVIA - LeadForge API: B2B lead generation + ICP + sequences - ProposalAI API: commercial proposal generator - BlueprintAI API: process/architecture document generator - MailWarm API: email warmup status/start/history - OutreachAI API: cold outreach sequences + subject lines - FormBuilder API: AI form generator - EmailVerify API: email validation (MX, disposable, format) - Auth OTP: replaces email-only auth with OTP/magic-link - SQL migration: auth_otp + auth_attempts tables - WEVIA proxy library: routes all AI calls through server-side Ollama - Auth library: API key validation + rate limiting via Redis Co-authored-by: Yacineutt <Yacineutt@users.noreply.github.com>
81 lines
2.4 KiB
PHP
81 lines
2.4 KiB
PHP
<?php
|
|
/**
|
|
* WEVIA API Proxy
|
|
* Routes SaaS product requests through the WEVIA engine
|
|
* Keeps API keys server-side only
|
|
*/
|
|
|
|
function weviaGenerate($systemPrompt, $userPrompt, $options = []) {
|
|
$timeout = $options['timeout'] ?? 120;
|
|
$maxTokens = $options['max_tokens'] ?? 4000;
|
|
|
|
$payload = json_encode([
|
|
'model' => 'qwen2.5:3b',
|
|
'messages' => [
|
|
['role' => 'system', 'content' => $systemPrompt],
|
|
['role' => 'user', 'content' => $userPrompt]
|
|
],
|
|
'max_tokens' => $maxTokens,
|
|
'temperature' => $options['temperature'] ?? 0.7,
|
|
'stream' => false
|
|
]);
|
|
|
|
$ch = curl_init('http://127.0.0.1:11434/v1/chat/completions');
|
|
curl_setopt_array($ch, [
|
|
CURLOPT_POST => true,
|
|
CURLOPT_POSTFIELDS => $payload,
|
|
CURLOPT_RETURNTRANSFER => true,
|
|
CURLOPT_TIMEOUT => $timeout,
|
|
CURLOPT_HTTPHEADER => [
|
|
'Content-Type: application/json'
|
|
]
|
|
]);
|
|
|
|
$response = curl_exec($ch);
|
|
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
|
$error = curl_error($ch);
|
|
curl_close($ch);
|
|
|
|
if ($error) {
|
|
return ['error' => 'Erreur generation: ' . $error, 'status' => 500];
|
|
}
|
|
|
|
if ($httpCode !== 200) {
|
|
return ['error' => 'Service IA indisponible (HTTP ' . $httpCode . ')', 'status' => $httpCode];
|
|
}
|
|
|
|
$data = json_decode($response, true);
|
|
$content = $data['choices'][0]['message']['content'] ?? '';
|
|
|
|
return [
|
|
'content' => $content,
|
|
'model' => $data['model'] ?? 'wevia',
|
|
'usage' => $data['usage'] ?? [],
|
|
'status' => 200
|
|
];
|
|
}
|
|
|
|
function contentFactoryGenerate($template, $topic, $language = 'fr', $extras = []) {
|
|
$ch = curl_init('http://127.0.0.1/api/content/generate.php');
|
|
curl_setopt_array($ch, [
|
|
CURLOPT_POST => true,
|
|
CURLOPT_POSTFIELDS => json_encode(array_merge([
|
|
'template' => $template,
|
|
'topic' => $topic,
|
|
'language' => $language
|
|
], $extras)),
|
|
CURLOPT_RETURNTRANSFER => true,
|
|
CURLOPT_TIMEOUT => 120,
|
|
CURLOPT_HTTPHEADER => [
|
|
'Content-Type: application/json',
|
|
'X-API-Key: ' . getenv('CONTENT_API_KEY')
|
|
]
|
|
]);
|
|
|
|
$response = curl_exec($ch);
|
|
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
|
curl_close($ch);
|
|
|
|
return json_decode($response, true);
|
|
}
|