This example shows how to use Athena’s language models directly when building with our TypeScript SDK. You can use the General Agent without tools to access models directly for simple text generation tasks.
Key features:
1 import type { AthenaIntelligence } from '@athenaintel/sdk'; 2 import { AthenaIntelligenceClient } from '@athenaintel/sdk'; 3 4 // Basic client setup (uses default production API) 5 const client = new AthenaIntelligenceClient({ 6 apiKey: process.env.ATHENA_API_KEY, 7 }); 8 9 // Override baseUrl for custom API endpoints 10 const customClient = new AthenaIntelligenceClient({ 11 apiKey: process.env.ATHENA_API_KEY, 12 baseUrl: 'https://your-custom-api.example.com', // Custom API endpoint 13 });
Use the General Agent without tools to access models directly:
1 const request: AthenaIntelligence.GeneralAgentRequest = { 2 config: { 3 model: 'gpt-4-turbo-preview', 4 }, 5 messages: [ 6 { 7 content: 'What is the capital of France?', 8 role: 'user', 9 type: 'user', 10 }, 11 ], 12 }; 13 14 const response = await client.agents.general.invoke(request); 15 console.log('Response:', JSON.stringify(response, null, 2));
Specify models explicitly in the config. Common models include:
1 // Use Claude models 2 const claudeRequest: AthenaIntelligence.GeneralAgentRequest = { 3 config: { 4 model: 'claude-3-5-sonnet-20241022', 5 }, 6 messages: [ 7 { 8 content: 'Who are you and what can you help me with?', 9 role: 'user', 10 type: 'user', 11 }, 12 ], 13 }; 14 15 const claudeResponse = await client.agents.general.invoke(claudeRequest); 16 17 // Use GPT models 18 const gptRequest: AthenaIntelligence.GeneralAgentRequest = { 19 config: { 20 model: 'gpt-4-turbo-preview', 21 }, 22 messages: [ 23 { 24 content: 'Explain quantum computing in simple terms', 25 role: 'user', 26 type: 'user', 27 }, 28 ], 29 }; 30 31 const gptResponse = await client.agents.general.invoke(gptRequest); 32 33 // Use other models 34 const mistralRequest: AthenaIntelligence.GeneralAgentRequest = { 35 config: { 36 model: 'mistral-large-2407', 37 }, 38 messages: [ 39 { 40 content: 'Write a haiku about programming', 41 role: 'user', 42 type: 'user', 43 }, 44 ], 45 }; 46 47 const mistralResponse = await client.agents.general.invoke(mistralRequest);
Use system messages to prime the model’s behavior:
1 const systemRequest: AthenaIntelligence.GeneralAgentRequest = { 2 config: { 3 model: 'gpt-4-turbo-preview', 4 }, 5 messages: [ 6 { 7 content: 'You are a helpful coding assistant specializing in TypeScript and Node.js.', 8 role: 'system', 9 type: 'system', 10 }, 11 { 12 content: 'How do I handle async errors in TypeScript?', 13 role: 'user', 14 type: 'user', 15 }, 16 ], 17 }; 18 19 const systemResponse = await client.agents.general.invoke(systemRequest); 20 console.log('System-primed response:', systemResponse);
Process multiple prompts efficiently using Promise.all:
1 const prompts = [ 2 'Explain the theory of relativity', 3 'What is machine learning?', 4 'How does photosynthesis work?', 5 'Describe the water cycle', 6 ]; 7 8 // Create requests for all prompts 9 const batchRequests = prompts.map(prompt => ({ 10 config: { 11 model: 'gpt-4-turbo-preview', 12 }, 13 messages: [ 14 { 15 content: prompt, 16 role: 'user', 17 type: 'user', 18 }, 19 ], 20 })); 21 22 // Process all requests in parallel 23 const batchPromises = batchRequests.map(request => 24 client.agents.general.invoke(request) 25 ); 26 27 const batchResults = await Promise.all(batchPromises); 28 29 // Process results 30 batchResults.forEach((result, index) => { 31 console.log(`Response ${index + 1} (${prompts[index]}):`); 32 console.log(JSON.stringify(result, null, 2)); 33 console.log('-'.repeat(50)); 34 });
Always include proper error handling for production applications:
1 import { AthenaIntelligenceError } from '@athenaintel/sdk'; 2 3 try { 4 const response = await client.agents.general.invoke({ 5 config: { 6 model: 'gpt-4-turbo-preview', 7 }, 8 messages: [ 9 { 10 content: 'Hello, world!', 11 role: 'user', 12 type: 'user', 13 }, 14 ], 15 }); 16 17 console.log('Response received:', response); 18 } catch (error) { 19 if (error instanceof AthenaIntelligenceError) { 20 console.error(`Athena API error (${error.statusCode}): ${error.message}`); 21 } else { 22 console.error('Unexpected error:', error); 23 } 24 }
Here’s a complete working example that demonstrates direct model usage:
1 import type { AthenaIntelligence } from '@athenaintel/sdk'; 2 import { AthenaIntelligenceClient, AthenaIntelligenceError } from '@athenaintel/sdk'; 3 4 async function runDirectModelExample() { 5 try { 6 const client = new AthenaIntelligenceClient({ 7 apiKey: process.env.ATHENA_API_KEY, 8 // Optional: override baseUrl for custom environments 9 // baseUrl: 'https://your-custom-api.example.com', 10 }); 11 12 // Simple text generation request 13 const request: AthenaIntelligence.GeneralAgentRequest = { 14 config: { 15 model: 'gpt-4-turbo-preview', 16 }, 17 messages: [ 18 { 19 content: 'You are a creative writing assistant.', 20 role: 'system', 21 type: 'system', 22 }, 23 { 24 content: 'Write a short story about a robot learning to paint', 25 role: 'user', 26 type: 'user', 27 }, 28 ], 29 }; 30 31 console.log('Sending request to model...'); 32 const response = await client.agents.general.invoke(request); 33 34 console.log('Response received:'); 35 console.log(JSON.stringify(response, null, 2)); 36 } catch (error) { 37 if (error instanceof AthenaIntelligenceError) { 38 console.error(`Athena API error (${error.statusCode}): ${error.message}`); 39 } else { 40 console.error('Unexpected error:', error); 41 } 42 } 43 } 44 45 runDirectModelExample();
