-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-with-real-key.js
More file actions
144 lines (122 loc) · 4.05 KB
/
test-with-real-key.js
File metadata and controls
144 lines (122 loc) · 4.05 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/**
* Test script for Rahyana API examples with real API key
*
* This script is for internal testing only and should not be published.
* It uses the real API key and localhost for testing.
*/
const API_KEY = 'rhy_zSTO_2mT83ta--Ud-a-ecB8SWv1vEYXQdd-_5aJbGMo'; // Real API key for testing
const BASE_URL = 'http://localhost:3000/api/v1'; // Local testing
async function testBasicChat() {
try {
console.log('🧪 Testing basic chat with GPT-5...');
const response = await fetch(`${BASE_URL}/chat/completions`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Content-Type': 'application/json',
'HTTP-Referer': 'https://test-app.com',
'X-Title': 'Rahyana Test'
},
body: JSON.stringify({
model: 'openai/gpt-5', // Testing with GPT-5
messages: [
{
role: 'user',
content: 'سلام! تست API با GPT-5'
}
],
stream: false,
max_tokens: 50
})
});
if (response.ok) {
const data = await response.json();
console.log('✅ Basic chat test passed');
console.log('Response:', data.choices[0].message.content);
return true;
} else {
console.log('❌ Basic chat test failed:', response.status);
const error = await response.text();
console.log('Error:', error);
return false;
}
} catch (error) {
console.log('❌ Basic chat test error:', error.message);
return false;
}
}
async function testModels() {
try {
console.log('🧪 Testing models endpoint...');
const response = await fetch(`${BASE_URL}/models`, {
method: 'GET',
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Content-Type': 'application/json'
}
});
if (response.ok) {
const data = await response.json();
console.log('✅ Models test passed');
console.log('Found', data.data ? data.data.length : 0, 'models');
// Check for GPT models
const gptModels = data.data ? data.data.filter(m => m.id && m.id.includes('gpt')) : [];
console.log('GPT models found:', gptModels.length);
gptModels.slice(0, 5).forEach(model => console.log(`- ${model.id}`)); // Show first 5
return true;
} else {
console.log('❌ Models test failed:', response.status);
return false;
}
} catch (error) {
console.log('❌ Models test error:', error.message);
return false;
}
}
async function testKeyInfo() {
try {
console.log('🧪 Testing key info endpoint...');
const response = await fetch(`${BASE_URL}/key`, {
method: 'GET',
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Content-Type': 'application/json'
}
});
if (response.ok) {
const data = await response.json();
console.log('✅ Key info test passed');
console.log('Key status:', data.data?.status);
return true;
} else {
console.log('❌ Key info test failed:', response.status);
return false;
}
} catch (error) {
console.log('❌ Key info test error:', error.message);
return false;
}
}
async function runTests() {
console.log('🚀 Testing Rahyana API with real key');
console.log('====================================');
const results = {
basicChat: await testBasicChat(),
models: await testModels(),
keyInfo: await testKeyInfo()
};
console.log('\n📊 Test Results:');
console.log('Basic Chat:', results.basicChat ? '✅ PASS' : '❌ FAIL');
console.log('Models:', results.models ? '✅ PASS' : '❌ FAIL');
console.log('Key Info:', results.keyInfo ? '✅ PASS' : '❌ FAIL');
const passed = Object.values(results).filter(Boolean).length;
const total = Object.keys(results).length;
console.log(`\n🎯 Overall: ${passed}/${total} tests passed`);
if (passed === total) {
console.log('🎉 All tests passed! Examples are ready for publication.');
} else {
console.log('⚠️ Some tests failed. Check server status.');
}
}
// Run tests
runTests().catch(console.error);