Files
html/api/ambre-tool-brainstorm.php
Opus d7871f7f73 feat(wevia-godmode-v3): 17 generators auto-intent router + 7 new premium APIs
NEW GENERATORS (V3 GODMODE):
- ambre-tool-3d.php: Three.js r128 scenes interactives (OrbitControls + anim loop + fog)
- ambre-tool-dataviz.php: Dashboards Plotly.js (3-4 charts + KPI cards + responsive grid)
- ambre-tool-site.php: Landing pages SaaS COMPLETES 10 sections (header/hero/features/pricing/FAQ/footer)
- ambre-tool-sql.php: NL -> SQL multi-dialect (PG/MySQL/SQLite) avec explanation + indexes suggested
- ambre-tool-brainstorm.php: Multi-IA PARALLELE 5 providers (cerebras+groq+sambanova+gemini+cloudflare) + synthese
- ambre-tool-image-gen.php: Text2Image avec cascade sovereign + fallback ambre-image
- ambre-tool-translate-code.php: Code translator multi-langages (Python/JS/TS/Go/Rust/Java/Ruby)

ROUTER V3:
- 17 generators catalogues (4 docs + 7 GODMODE + 6 utilities)
- detectIntent() NL regex français/anglais
- extractPayload() nettoyage intelligent
- Rendering adapte par kind: docx/xlsx/pptx/react (preview panel), 3d (three.js iframe), image (inline img), code (pre+copy btn), json (summary card OR brainstorm providers_used), inline (calc), audio (player)

SAFETY PUBLIC:
- Zero secret WEVAL divulgue dans prompts
- Zero acces vault/credentials/serveurs internes
- Sovereign cascade uniquement (0€ LLM cost)
- Tous prompts contraints 'info generique safe'

TESTED LIVE:
- SQL generator PostgreSQL validated (json_agg + INNER JOIN + GROUP BY)
- DOCX 7 sections + XLSX 3 sheets + PPTX 10 slides + REACT standalone (all previously tested 1d24e243c commit)

17 intents auto-detectes dans wevia.html public widget.
WEVIA public maintenant aussi capable qu'un copilot grand public tout en restant safe sur secrets WEVAL.
2026-04-24 21:44:55 +02:00

115 lines
3.8 KiB
PHP

<?php
/**
* ambre-tool-brainstorm.php — Multi-IA Brainstorm (parallel cascade)
* Envoie la même question à 3-5 providers sovereign en parallèle
* Synthétise les réponses en 1 output unifié
* Input: JSON {topic}
* Output: JSON {ok, summary, providers_used, raw_responses}
*/
header('Content-Type: application/json');
if ($_SERVER['REQUEST_METHOD'] !== 'POST') { echo json_encode(['ok'=>false,'error'=>'POST only']); exit; }
$input = json_decode(file_get_contents('php://input'), true);
$topic = trim($input['topic'] ?? $input['query'] ?? '');
if (strlen($topic) < 5) { echo json_encode(['ok'=>false,'error'=>'topic too short']); exit; }
$topic = substr($topic, 0, 800);
// Providers to query in parallel (sovereign cascade exposes these)
$providers = [
'cerebras' => 'llama-3.3-70b',
'groq' => 'llama-3.3-70b-versatile',
'sambanova' => 'Meta-Llama-3.3-70B-Instruct',
'gemini' => 'gemini-2.0-flash-exp',
'cloudflare' => 'llama-3.3-70b-instruct',
];
$prompt = "Perspective sur: \"$topic\"\n\nDonne UNE idee/angle/insight unique et original en 3-5 phrases maximum. Pas d'intro, va direct a l'insight.";
$mh = curl_multi_init();
$handles = [];
foreach ($providers as $prov => $model) {
$ch = curl_init('http://127.0.0.1:4000/v1/chat/completions');
curl_setopt_array($ch, [
CURLOPT_POST => true, CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => json_encode([
'model' => $model,
'provider' => $prov,
'messages' => [['role'=>'user', 'content'=>$prompt]],
'max_tokens' => 400,
'temperature' => 0.85
]),
CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
CURLOPT_TIMEOUT => 30,
]);
curl_multi_add_handle($mh, $ch);
$handles[$prov] = $ch;
}
// Execute parallel
$running = null;
do {
curl_multi_exec($mh, $running);
curl_multi_select($mh, 0.1);
} while ($running > 0);
$responses = [];
$successful = 0;
foreach ($handles as $prov => $ch) {
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$body = curl_multi_getcontent($ch);
if ($code === 200) {
$data = json_decode($body, true);
$content = $data['choices'][0]['message']['content'] ?? '';
if ($content) {
$responses[$prov] = substr(trim($content), 0, 800);
$successful++;
}
}
curl_multi_remove_handle($mh, $ch);
curl_close($ch);
}
curl_multi_close($mh);
if ($successful === 0) {
echo json_encode(['ok'=>false, 'error'=>'All providers failed']);
exit;
}
// Synthesis via 1 additional provider
$synth_input = "Synthetise les perspectives suivantes en 1 resume structure et enrichi:\n\n";
foreach ($responses as $prov => $resp) {
$synth_input .= "### $prov\n$resp\n\n";
}
$synth_input .= "\n\nFormat reponse:\n- 3-5 points cles majeurs (bullets)\n- 1 paragraphe synthese (4-6 phrases)\n- Pas d'intro type 'voici la synthese'";
$ch = curl_init('http://127.0.0.1:4000/v1/chat/completions');
curl_setopt_array($ch, [
CURLOPT_POST => true, CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => json_encode([
'model' => 'auto',
'messages' => [['role'=>'user', 'content'=>$synth_input]],
'max_tokens' => 1200,
'temperature' => 0.5
]),
CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
CURLOPT_TIMEOUT => 45,
]);
$synth_raw = curl_exec($ch);
$synth_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
$synthesis = '';
if ($synth_code === 200) {
$synth_data = json_decode($synth_raw, true);
$synthesis = $synth_data['choices'][0]['message']['content'] ?? '';
}
echo json_encode([
'ok' => true,
'summary' => $synthesis ?: 'Synthese indisponible - voir raw_responses',
'providers_used' => array_keys($responses),
'providers_count' => $successful,
'raw_responses' => $responses,
'topic' => $topic,
]);