Files
wevia-brain/integrate.sh
2026-04-12 23:01:36 +02:00

59 lines
2.1 KiB
Bash
Executable File

#!/bin/bash
# Integration script — connects brain to WEVIA
echo "=== INTEGRATING BRAIN TO WEVIA ==="
# Create symlink from web root to brain API
WEB_ROOT="/var/www/weval/wevia-ia"
if [ -d "$WEB_ROOT" ]; then
ln -sf /opt/wevia-brain/modules/api-wrapper.php "$WEB_ROOT/brain-api.php"
echo "✅ Symlink: $WEB_ROOT/brain-api.php → brain modules"
fi
# Create PHP autoloader for brain modules
cat > /opt/wevia-brain/autoload.php << 'AUTOEOF'
<?php
spl_autoload_register(function($class) {
$map = [
'ChainOfThought' => '/opt/wevia-brain/modules/chain-of-thought.php',
'MultiPerspective' => '/opt/wevia-brain/modules/chain-of-thought.php',
'SelfCorrection' => '/opt/wevia-brain/modules/chain-of-thought.php',
'RAGEngine' => '/opt/wevia-brain/modules/rag-engine.php',
'ToolUseEngine' => '/opt/wevia-brain/modules/tool-use-engine.php',
'OpusOrchestrator' => '/opt/wevia-brain/modules/opus-orchestrator.php'
];
if (isset($map[$class])) require_once $map[$class];
});
AUTOEOF
echo "✅ autoload.php created"
# Load all KB JSON into PostgreSQL for RAG ingestion
php -r "
require_once '/opt/wevia-brain/modules/rag-engine.php';
try {
\$pdo = new PDO('pgsql:host=127.0.0.1;dbname=wevia_db', 'postgres', '');
\$rag = new RAGEngine(\$pdo);
\$kbDir = '/opt/wevia-brain/knowledge/';
\$total = 0;
foreach (glob(\$kbDir . '*.json') as \$file) {
\$name = basename(\$file, '.json');
\$content = file_get_contents(\$file);
// Flatten JSON to text for embedding
\$flat = json_encode(json_decode(\$content, true), JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
\$chunks = \$rag->ingest(\$flat, \$name, 'weval_kb');
echo \" \$name: \$chunks chunks ingested\n\";
\$total += \$chunks;
}
echo \"TOTAL: \$total chunks ingested into pgvector\n\";
} catch (Exception \$e) {
echo 'RAG ingestion error: ' . \$e->getMessage() . \"\n\";
}
" 2>&1
echo ""
echo "=== INTEGRATION COMPLETE ==="