Repository navigation
Expand file tree
/
Copy pathexample.php
More file actions
89 lines (76 loc) · 2.69 KB
/
Copy pathexample.php
File metadata and controls
89 lines (76 loc) · 2.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
/*
* Copyright M. Bryce Hudson 2026-2029 All Rights Reserved
*
* Unauthorized reproduction, distribution, or transmission of the work is prohibited without prior written permission, with exceptions for brief quotations and specific noncommercial uses under copyright law.
*
* BryceFromIndiana@gmail.com
*/
/**
* Router Module Integration Example
*
* This file demonstrates how to integrate the router module into any PHP application.
* Copy this pattern to your own PHP files where you need multi-model AI capabilities.
*/
// Step 1: Include the router autoloader
require_once __DIR__ . '/autoload.php';
// Step 2: Import the classes you need
use Src\Config;
use Src\ModelManager;
use Src\SessionManager;
use Src\TopologyGraph;
// Step 3: Use the router functionality
// Example 1: Get all configured models
$models = Config::getModels();
echo "Available models:\n";
foreach ($models as $model) {
echo "- {$model['name']} ({$model['provider']})\n";
}
// Example 2: Create a new session
$sessionId = SessionManager::createSession("My Coding Session");
echo "\nCreated session: $sessionId\n";
// Example 3: Process a query through active models
$manager = new ModelManager();
$results = $manager->processRequest("Write a PHP function to validate email addresses");
if (!empty($results)) {
foreach ($results as $result) {
echo "\nResponse from {$result['model_name']} ({$result['role']}):\n";
echo substr($result['response'], 0, 200) . "...\n";
}
}
// Example 4: Get topology data for visualization
$sessions = SessionManager::getSessions();
$topology = TopologyGraph::generateGraphData($sessions);
echo "\nTopology: " . count($topology['nodes']) . " nodes, " . count($topology['edges']) . " connections\n";
// Example 5: Add a new model programmatically
if (false) { // Set to true to test
Config::addModel([
'name' => 'Local Code Llama',
'provider' => 'ollama',
'endpoint' => 'http://localhost:11434/api/generate',
'model' => 'codellama:13b-code',
'api_key' => '',
'priority' => 5,
'role' => 'coder',
'active' => true
]);
echo "Added new model\n";
}
// Example 6: Export a session
if (isset($_GET['export'])) {
$sessionId = $_GET['export'];
$session = SessionManager::getSession($sessionId);
if ($session) {
echo "<pre>" . json_encode($session, JSON_PRETTY_PRINT) . "</pre>";
}
}
// Example 7: Check router status
$config = Config::loadConfig();
$status = [
'theme' => $config['theme'] ?? 'neon',
'sounds_enabled' => $config['sounds_enabled'] ?? true,
'active_models' => count(array_filter(Config::getModels(), fn($m) => $m['active']))
];
echo "\nRouter Status:\n";
print_r($status);
?>