-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic-usage.js
More file actions
71 lines (60 loc) · 2.13 KB
/
Copy pathbasic-usage.js
File metadata and controls
71 lines (60 loc) · 2.13 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
/**
* Basic Usage Example - AetherGuard SDK
*
* Prerequisites:
* 1. Sign up at https://portal.aetherguard.ai
* 2. Add a provider, register a model, and generate an API key
* 3. Set AETHERGUARD_API_KEY and AETHERGUARD_BASE_URL env vars
*/
const { AetherGuardClient } = require('@aetherguard/sdk');
async function basicExample() {
const client = new AetherGuardClient({
apiKey: process.env.AETHERGUARD_API_KEY || 'your-api-key-here',
baseUrl: process.env.AETHERGUARD_BASE_URL || 'http://localhost:8080',
debug: true
});
try {
// Test connection to the proxy
console.log('Testing connection...');
const isConnected = await client.testConnection();
console.log('Connected:', isConnected);
if (!isConnected) {
console.error('Cannot reach AetherGuard proxy. Check your AETHERGUARD_BASE_URL.');
return;
}
// Simple chat completion
console.log('\n--- Chat Completion ---');
const response = await client.createChatCompletion({
model: 'gpt-4',
messages: [
{ role: 'system', content: 'You are a helpful assistant.' },
{ role: 'user', content: 'What is artificial intelligence?' }
],
max_tokens: 150,
temperature: 0.7
});
console.log('Response:', response.choices[0].message.content);
console.log('Tokens used:', response.usage);
console.log('Finish reason:', response.choices[0].finish_reason);
// Simple completion (non-chat)
console.log('\n--- Simple Completion ---');
const simple = await client.createCompletion({
model: 'gpt-4',
prompt: 'Explain machine learning in one sentence.',
max_tokens: 50
});
console.log('Response:', simple.choices[0].message.content);
// Check proxy status
console.log('\n--- Proxy Status ---');
const status = await client.getStatus();
console.log('Pipeline:', status.pipeline);
console.log('Stages:', status.stages.join(' → '));
} catch (error) {
if (error.code === 'CONTENT_BLOCKED') {
console.log('Request blocked by security pipeline:', error.message);
} else {
console.error('Error:', error);
}
}
}
basicExample();