-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathmistral-basic.ts
More file actions
69 lines (57 loc) · 2.35 KB
/
Copy pathmistral-basic.ts
File metadata and controls
69 lines (57 loc) · 2.35 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
/**
* Mistral AI Basic Example
*
* Demonstrates basic usage of TealMistral client with European data residency
*/
import { TealMistral } from 'tealtiger';
async function main() {
// Initialize TealMistral client
const client = new TealMistral({
apiKey: process.env.MISTRAL_API_KEY || 'your-mistral-api-key',
agentId: 'mistral-demo-agent',
});
console.log('🇪🇺 TealTiger Mistral AI Basic Example\n');
try {
// Simple chat completion with Mistral Large
console.log('📝 Sending chat completion request (Mistral Large)...');
const response = await client.chat.completions.create({
model: 'mistral-large-latest',
messages: [
{ role: 'system', content: 'You are a helpful assistant focused on European data privacy.' },
{ role: 'user', content: 'Explain GDPR compliance in simple terms.' },
],
max_tokens: 200,
});
console.log('\n✅ Response received:');
console.log(response.choices[0].message.content);
// Display cost and token usage
if (response.security?.costRecord) {
console.log('\n💰 Cost Information:');
console.log(` Cost: $${response.security.costRecord.actualCost.toFixed(6)}`);
console.log(` Input Tokens: ${response.security.costRecord.actualTokens.inputTokens}`);
console.log(` Output Tokens: ${response.security.costRecord.actualTokens.outputTokens}`);
}
// Try Mistral Small for cost-effective queries
console.log('\n📝 Sending request with Mistral Small (cost-effective)...');
const smallResponse = await client.chat.completions.create({
model: 'mistral-small-latest',
messages: [
{ role: 'user', content: 'What is the capital of France?' },
],
max_tokens: 50,
});
console.log('\n✅ Response received:');
console.log(smallResponse.choices[0].message.content);
if (smallResponse.security?.costRecord) {
console.log(` 💰 Cost: $${smallResponse.security.costRecord.actualCost.toFixed(6)}`);
}
// Display European data residency information
console.log('\n🇪🇺 European Data Residency:');
console.log(' ✓ Data processed in European data centers');
console.log(' ✓ GDPR compliant');
console.log(' ✓ No data transfer outside EU');
} catch (error) {
console.error('❌ Error:', error instanceof Error ? error.message : error);
}
}
main();