-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic-usage.js
More file actions
59 lines (48 loc) · 1.65 KB
/
basic-usage.js
File metadata and controls
59 lines (48 loc) · 1.65 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
/**
* Basic Usage Example - AetherGuard Node.js SDK
*/
const { AetherGuardClient } = require('@aetherguard/nodejs-sdk');
async function basicExample() {
// Initialize the client
const client = new AetherGuardClient({
apiKey: 'your-api-key-here',
baseUrl: process.env.AETHERGUARD_BASE_URL || 'http://localhost:8080',
debug: true // Optional: enable debug logging
});
try {
// Test connection
console.log('Testing connection...');
const isConnected = await client.testConnection();
console.log('Connected:', isConnected);
// Simple chat completion
console.log('\n--- Simple Chat Completion ---');
const response = await client.createChatCompletion({
model: 'gpt-3.5-turbo',
messages: [
{ role: 'user', content: 'What is artificial intelligence?' }
],
max_tokens: 150
});
console.log('Response:', response.choices[0].message.content);
console.log('Usage:', response.usage);
// Security scanning
console.log('\n--- Security Scanning ---');
const scanResult = await client.scanText({
text: 'This is a test message for security scanning',
scanTypes: ['toxicity', 'injection', 'pii']
});
console.log('Security scan result:', scanResult);
// Get usage metrics
console.log('\n--- Usage Metrics ---');
const metrics = await client.getUsageMetrics();
console.log('Usage metrics:', metrics);
// Get API key info
console.log('\n--- API Key Info ---');
const keyInfo = await client.getApiKeyInfo();
console.log('API Key info:', keyInfo);
} catch (error) {
console.error('Error:', error);
}
}
// Run the example
basicExample();