forked from google-gemini/gemini-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_cli_proxy.js
More file actions
84 lines (70 loc) · 2.32 KB
/
test_cli_proxy.js
File metadata and controls
84 lines (70 loc) · 2.32 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
#!/usr/bin/env node
/**
* Test script to verify CLI can communicate through proxy server
*/
import fetch from 'node-fetch';
const TEST_ENDPOINT = 'http://127.0.0.1:3458/v1beta/models/gemini-pro/generateContent';
const API_KEY = 'AIzaSyBGVrcTiEDko1jZW0wmaGC_oYxK-AL3mEQ';
const testRequest = {
contents: [
{
parts: [
{
text: "Please respond with exactly: 'CLI proxy test successful!'"
}
],
role: 'user'
}
],
generationConfig: {
temperature: 0.1,
maxOutputTokens: 50
}
};
async function testCliProxy() {
console.log('🧪 Testing CLI → Proxy Server → SHUAIHONG API...\n');
try {
console.log(`📡 Sending request to: ${TEST_ENDPOINT}`);
console.log(`🔑 Using API Key: ${API_KEY.substring(0, 10)}...`);
console.log(`📝 Request:`, JSON.stringify(testRequest, null, 2));
const response = await fetch(TEST_ENDPOINT, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'x-goog-api-key': API_KEY
},
body: JSON.stringify(testRequest)
});
console.log(`\n📊 Response Status: ${response.status} ${response.statusText}`);
if (!response.ok) {
const errorText = await response.text();
console.error('❌ Request failed:', errorText);
return false;
}
const result = await response.json();
console.log('✅ Response received:');
console.log(JSON.stringify(result, null, 2));
// Check if response has expected structure
if (result.candidates && result.candidates[0] && result.candidates[0].content) {
const responseText = result.candidates[0].content.parts[0].text;
console.log(`\n💬 AI Response: "${responseText}"`);
if (responseText.includes('CLI proxy test successful')) {
console.log('✅ Test PASSED: CLI ↔ Proxy ↔ SHUAIHONG communication works!');
return true;
} else {
console.log('⚠️ Test PARTIAL: Communication works but response content unexpected');
return true;
}
} else {
console.log('❌ Test FAILED: Invalid response structure');
return false;
}
} catch (error) {
console.error('❌ Test FAILED:', error.message);
return false;
}
}
// Run the test
testCliProxy().then(success => {
process.exit(success ? 0 : 1);
});