-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest-node.js
More file actions
executable file
Β·187 lines (159 loc) Β· 5.2 KB
/
test-node.js
File metadata and controls
executable file
Β·187 lines (159 loc) Β· 5.2 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#!/usr/bin/env node
/**
* Simple test script for Helicone n8n node
* This script tests the basic functionality without requiring n8n
*/
const https = require('https');
// Configuration - Update these with your actual keys
const config = {
heliconeApiKey: process.env.HELICONE_API_KEY || 'your-helicone-api-key',
openaiApiKey: process.env.OPENAI_API_KEY || 'your-openai-api-key',
anthropicApiKey: process.env.ANTHROPIC_API_KEY || 'your-anthropic-api-key'
};
function makeRequest(url, headers, body) {
return new Promise((resolve, reject) => {
const data = JSON.stringify(body);
const options = {
method: 'POST',
headers: {
...headers,
'Content-Length': Buffer.byteLength(data)
}
};
const req = https.request(url, options, (res) => {
let responseData = '';
res.on('data', (chunk) => {
responseData += chunk;
});
res.on('end', () => {
try {
const parsed = JSON.parse(responseData);
resolve({
statusCode: res.statusCode,
headers: res.headers,
data: parsed
});
} catch (error) {
resolve({
statusCode: res.statusCode,
headers: res.headers,
data: responseData
});
}
});
});
req.on('error', (error) => {
reject(error);
});
req.write(data);
req.end();
});
}
async function testOpenAI() {
console.log('π§ͺ Testing OpenAI through Helicone...');
const url = 'https://oai.helicone.ai/v1/chat/completions';
const headers = {
'Content-Type': 'application/json',
'Authorization': `Bearer ${config.openaiApiKey}`,
'Helicone-Auth': `Bearer ${config.heliconeApiKey}`,
'Helicone-Property-test': 'true',
'Helicone-Property-environment': 'testing',
'Helicone-Session-Id': 'test-session-123',
'Helicone-Session-Name': 'Node Test Session'
};
const body = {
model: 'gpt-4o-mini',
messages: [
{ role: 'user', content: 'Hello! Please tell me a short joke.' }
],
max_tokens: 100,
temperature: 0.7
};
try {
const response = await makeRequest(url, headers, body);
console.log('β
OpenAI test successful!');
console.log('Status:', response.statusCode);
console.log('Response:', JSON.stringify(response.data, null, 2));
return true;
} catch (error) {
console.error('β OpenAI test failed:', error.message);
return false;
}
}
async function testAnthropic() {
console.log('\nπ§ͺ Testing Anthropic through Helicone...');
const url = 'https://anthropic.helicone.ai/v1/messages';
const headers = {
'Content-Type': 'application/json',
'x-api-key': config.anthropicApiKey,
'anthropic-version': '2023-06-01',
'Helicone-Auth': `Bearer ${config.heliconeApiKey}`,
'Helicone-Property-test': 'true',
'Helicone-Property-environment': 'testing',
'Helicone-Session-Id': 'test-session-456',
'Helicone-Session-Name': 'Anthropic Test Session'
};
const body = {
model: 'claude-3-opus-20240229',
messages: [
{ role: 'user', content: 'Hello! Please tell me a short joke.' }
],
max_tokens: 100,
temperature: 0.7,
system: 'You are a helpful assistant.'
};
try {
const response = await makeRequest(url, headers, body);
console.log('β
Anthropic test successful!');
console.log('Status:', response.statusCode);
console.log('Response:', JSON.stringify(response.data, null, 2));
return true;
} catch (error) {
console.error('β Anthropic test failed:', error.message);
return false;
}
}
async function runTests() {
console.log('π Starting Helicone n8n Node Tests\n');
// Check if API keys are configured
if (!config.heliconeApiKey || config.heliconeApiKey === 'your-helicone-api-key') {
console.error('β Please set HELICONE_API_KEY environment variable');
process.exit(1);
}
if (!config.openaiApiKey || config.openaiApiKey === 'your-openai-api-key') {
console.error('β Please set OPENAI_API_KEY environment variable');
process.exit(1);
}
const results = {
openai: false,
anthropic: false
};
// Test OpenAI
results.openai = await testOpenAI();
// Test Anthropic (optional)
if (config.anthropicApiKey && config.anthropicApiKey !== 'your-anthropic-api-key') {
results.anthropic = await testAnthropic();
} else {
console.log('\nβοΈ Skipping Anthropic test (no API key provided)');
}
// Summary
console.log('\nπ Test Results:');
console.log('OpenAI:', results.openai ? 'β
PASS' : 'β FAIL');
console.log('Anthropic:', results.anthropic ? 'β
PASS' : 'βοΈ SKIP');
if (results.openai) {
console.log('\nπ Basic functionality test passed!');
console.log('π‘ Next steps:');
console.log(' 1. Open n8n at http://localhost:5678');
console.log(' 2. Create a new workflow');
console.log(' 3. Add the Helicone node');
console.log(' 4. Configure credentials and test');
} else {
console.log('\nβ Tests failed. Please check your API keys and try again.');
process.exit(1);
}
}
// Run tests if this script is executed directly
if (require.main === module) {
runTests().catch(console.error);
}
module.exports = { testOpenAI, testAnthropic };