Repository navigation
Expand file tree
/
Copy pathlist_models.php
More file actions
104 lines (83 loc) · 3.76 KB
/
Copy pathlist_models.php
File metadata and controls
104 lines (83 loc) · 3.76 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
// Script to list all available Gemini models
error_reporting(E_ALL);
ini_set('display_errors', 1);
echo "<h2>Gemini API - Available Models</h2>";
// Load API key from .env
$envFile = __DIR__ . '/.env';
$apiKey = '';
if (file_exists($envFile)) {
$envContent = file_get_contents($envFile);
if (preg_match('/GEMINI_API_KEY\s*=\s*["\']?([^"\'\r\n]+)["\']?/', $envContent, $matches)) {
$apiKey = trim($matches[1], '"\'');
}
}
if (empty($apiKey)) {
die("<p style='color:red;'>ERROR: API key not found in .env file</p>");
}
echo "<p><strong>API Key loaded:</strong> " . substr($apiKey, 0, 10) . "..." . substr($apiKey, -5) . "</p>";
// List models endpoint
$url = "https://generativelanguage.googleapis.com/v1beta/models?key=$apiKey";
echo "<p><strong>Fetching available models...</strong></p>";
$options = [
'http' => [
'method' => 'GET',
'header' => "Content-Type: application/json\r\n",
'ignore_errors' => true,
'timeout' => 30
]
];
$context = stream_context_create($options);
$result = @file_get_contents($url, false, $context);
if ($result === false) {
$error = error_get_last();
echo "<p style='color:red;'><strong>ERROR: Connection failed</strong></p>";
echo "<pre>" . htmlspecialchars(print_r($error, true)) . "</pre>";
exit;
}
$response = json_decode($result, true);
if (isset($response['error'])) {
echo "<p style='color:red;'><strong>API Error:</strong></p>";
echo "<pre>" . htmlspecialchars(json_encode($response['error'], JSON_PRETTY_PRINT)) . "</pre>";
exit;
}
echo "<p style='color:green;'><strong>SUCCESS: Models retrieved</strong></p>";
if (isset($response['models'])) {
echo "<h3>Available Models for Content Generation:</h3>";
echo "<table border='1' cellpadding='10' style='border-collapse:collapse; width:100%;'>";
echo "<tr style='background:#f0f0f0;'><th>Model Name</th><th>Display Name</th><th>Supported Methods</th><th>Description</th></tr>";
foreach ($response['models'] as $model) {
$name = $model['name'] ?? 'N/A';
$displayName = $model['displayName'] ?? 'N/A';
$supportedMethods = isset($model['supportedGenerationMethods']) ? implode(', ', $model['supportedGenerationMethods']) : 'N/A';
$description = $model['description'] ?? 'No description';
// Highlight models that support generateContent
$highlight = '';
if (isset($model['supportedGenerationMethods']) && in_array('generateContent', $model['supportedGenerationMethods'])) {
$highlight = ' style="background:#d4edda;"';
}
echo "<tr{$highlight}>";
echo "<td><strong>" . htmlspecialchars($name) . "</strong></td>";
echo "<td>" . htmlspecialchars($displayName) . "</td>";
echo "<td>" . htmlspecialchars($supportedMethods) . "</td>";
echo "<td>" . htmlspecialchars($description) . "</td>";
echo "</tr>";
}
echo "</table>";
echo "<p style='margin-top:20px;'><strong>Note:</strong> Models highlighted in green support the 'generateContent' method.</p>";
// Recommend a model
echo "<h3>Recommended Models for CTF Flag Generation:</h3>";
echo "<ul>";
foreach ($response['models'] as $model) {
if (isset($model['supportedGenerationMethods']) && in_array('generateContent', $model['supportedGenerationMethods'])) {
$name = $model['name'];
$displayName = $model['displayName'] ?? $name;
echo "<li><strong>" . htmlspecialchars($displayName) . "</strong> - <code>" . htmlspecialchars($name) . "</code></li>";
}
}
echo "</ul>";
} else {
echo "<p style='color:red;'>No models found in response</p>";
echo "<pre>" . htmlspecialchars(json_encode($response, JSON_PRETTY_PRINT)) . "</pre>";
}
?>