-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-javascript-examples.js
More file actions
100 lines (81 loc) · 2.83 KB
/
test-javascript-examples.js
File metadata and controls
100 lines (81 loc) · 2.83 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
/**
* Test the actual JavaScript examples with real API key
*/
const API_KEY = 'rhy_zSTO_2mT83ta--Ud-a-ecB8SWv1vEYXQdd-_5aJbGMo';
const BASE_URL = 'http://localhost:3000/api/v1';
// Test the models example
async function testModelsExample() {
try {
console.log('🧪 Testing JavaScript models example...');
const response = await fetch(`${BASE_URL}/models`, {
method: 'GET',
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Content-Type': 'application/json',
'HTTP-Referer': 'https://example-app.com',
'X-Title': 'Rahyana Models Example'
}
});
if (!response.ok) {
throw new Error(`خطای HTTP! وضعیت: ${response.status}`);
}
const data = await response.json();
console.log('✅ Models example works correctly');
console.log('Found', data.data ? data.data.length : 0, 'models');
if (data.data && Array.isArray(data.data)) {
console.log('Sample models:');
data.data.slice(0, 3).forEach((model, index) => {
console.log(`${index + 1}. ${model.id}`);
});
}
return true;
} catch (error) {
console.log('❌ Models example failed:', error.message);
return false;
}
}
// Test the key info example
async function testKeyInfoExample() {
try {
console.log('🧪 Testing JavaScript key info example...');
const response = await fetch(`${BASE_URL}/key`, {
method: 'GET',
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Content-Type': 'application/json',
'HTTP-Referer': 'https://example-app.com',
'X-Title': 'Rahyana API Key Example'
}
});
if (!response.ok) {
throw new Error(`خطای HTTP! وضعیت: ${response.status}`);
}
const data = await response.json();
console.log('✅ Key info example works correctly');
console.log('Key data received:', !!data.data);
return true;
} catch (error) {
console.log('❌ Key info example failed:', error.message);
return false;
}
}
async function runTests() {
console.log('🚀 Testing JavaScript Examples');
console.log('==============================');
const results = {
models: await testModelsExample(),
keyInfo: await testKeyInfoExample()
};
console.log('\n📊 Test Results:');
console.log('Models Example:', results.models ? '✅ PASS' : '❌ FAIL');
console.log('Key Info Example:', results.keyInfo ? '✅ PASS' : '❌ FAIL');
const passed = Object.values(results).filter(Boolean).length;
const total = Object.keys(results).length;
console.log(`\n🎯 Overall: ${passed}/${total} examples working`);
if (passed === total) {
console.log('🎉 All JavaScript examples are working correctly!');
} else {
console.log('⚠️ Some examples have issues, but this is likely server-side.');
}
}
runTests().catch(console.error);