-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathcohere-basic.ts
More file actions
67 lines (55 loc) · 2.11 KB
/
Copy pathcohere-basic.ts
File metadata and controls
67 lines (55 loc) · 2.11 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
/**
* Cohere Basic Example
*
* Demonstrates basic usage of TealCohere client for chat and embeddings
*/
import { TealCohere } from 'tealtiger';
async function main() {
// Initialize TealCohere client
const client = new TealCohere({
apiKey: process.env.COHERE_API_KEY || 'your-cohere-api-key',
agentId: 'cohere-demo-agent',
});
console.log('🔵 TealTiger Cohere Basic Example\n');
try {
// Simple chat completion
console.log('📝 Sending chat request...');
const chatResponse = await client.chat({
message: 'What are the key features of Cohere AI?',
model: 'command',
});
console.log('\n✅ Chat Response:');
console.log(chatResponse.text);
// Display cost information
if (chatResponse.security?.costRecord) {
console.log('\n💰 Cost Information:');
console.log(` Cost: $${chatResponse.security.costRecord.actualCost.toFixed(6)}`);
console.log(` Tokens: ${chatResponse.security.costRecord.actualTokens.totalTokens}`);
}
// Generate embeddings
console.log('\n📊 Generating embeddings...');
const embedResponse = await client.embed({
texts: [
'Machine learning is fascinating',
'Natural language processing enables AI to understand text',
'Deep learning powers modern AI systems',
],
model: 'embed-english-v3.0',
});
console.log('\n✅ Embeddings generated:');
console.log(` Number of embeddings: ${embedResponse.embeddings.length}`);
console.log(` Embedding dimension: ${embedResponse.embeddings[0].length}`);
if (embedResponse.security?.costRecord) {
console.log(` 💰 Cost: $${embedResponse.security.costRecord.actualCost.toFixed(6)}`);
}
// Display Cohere features
console.log('\n🔵 Cohere Features:');
console.log(' ✓ Enterprise-grade chat models');
console.log(' ✓ High-quality embeddings');
console.log(' ✓ RAG (Retrieval Augmented Generation) support');
console.log(' ✓ Built-in connectors for web search');
} catch (error) {
console.error('❌ Error:', error instanceof Error ? error.message : error);
}
}
main();