Getting Started with SakshWallet: AI Reporting Methods and Examples

Susheel kumar - Sep 8 - - Dev Community

Formatted version of the examples to help users understand how to use the saksh-wallet class, including the AI reporting functionalities.

Example Usage

  1. Setting the Gemini AI Key
   const SakshWallet = require('saksh-wallet');
   const wallet = new SakshWallet();

   async function setAIKeyExample() {
       const geminiAIKey = 'your-gemini-ai-key';
       const aiModel = 'text-davinci-003';
       const maxTokens = 150;
       await wallet.sakshGeminiAIKey(geminiAIKey, aiModel, maxTokens);
       console.log('AI key set successfully.');
   }

   setAIKeyExample();
Enter fullscreen mode Exit fullscreen mode
  1. Generating a Report Summary
   const wallet = new SakshWallet();

   async function generateReportSummaryExample() {
       const transactions = [
           { date: new Date(), type: 'credit', amount: 100, currency: 'USD', description: 'Test transaction' },
           { date: new Date(), type: 'debit', amount: 50, currency: 'USD', description: 'Grocery shopping' }
       ];
       const summary = await wallet.sakshGenerateReportSummary(transactions);
       console.log('Report Summary:', summary);
   }

   generateReportSummaryExample();
Enter fullscreen mode Exit fullscreen mode
  1. Handling a User Query
   const wallet = new SakshWallet();

   async function handleUserQueryExample() {
       const query = 'Show me all transactions for user123 in August 2024';
       const result = await wallet.sakshHandleUserQuery(query);
       console.log('Query Result:', result);
   }

   handleUserQueryExample();
Enter fullscreen mode Exit fullscreen mode
  1. Generating a Comprehensive Report
   const wallet = new SakshWallet();

   async function generateReportExample() {
       const prompt = 'Generate a monthly transaction report for user123 for August 2024';
       const userId = 'user123';
       const report = await wallet.sakshGenerateReport(prompt, userId);
       console.log('Generated Report:', report);
   }

   generateReportExample();
Enter fullscreen mode Exit fullscreen mode

Event Handling Example

You can also listen for events emitted by the SakshAIReporting class:

const SakshWallet = require('saksh-wallet');
const wallet = new SakshWallet();

wallet.aiReporting.on('aiKeySet', (data) => {
    console.log('AI Key Set:', data);
});

wallet.aiReporting.on('reportSummaryGenerated', (data) => {
    console.log('Report Summary Generated:', data);
});

wallet.aiReporting.on('userQueryHandled', (data) => {
    console.log('User Query Handled:', data);
});

wallet.aiReporting.on('queryExecutionFailed', (data) => {
    console.error('Query Execution Failed:', data);
});

wallet.aiReporting.on('dataFetchFailed', (data) => {
    console.error('Data Fetch Failed:', data);
});

wallet.aiReporting.on('reportGenerated', (data) => {
    console.log('Report Generated:', data);
});

wallet.aiReporting.on('reportGenerationFailed', (data) => {
    console.error('Report Generation Failed:', data);
});

// Example: Setting the AI key
wallet.sakshGeminiAIKey('your-gemini-ai-key', 'text-davinci-003', 150);

// Example: Generating a report summary
wallet.sakshGenerateReportSummary([{ date: new Date(), type: 'credit', amount: 100, currency: 'USD', description: 'Test transaction' }]);
Enter fullscreen mode Exit fullscreen mode

These examples demonstrate how to use the various functionalities of the saksh-wallet class, including the AI-enhanced reporting features. Let me know if you need any further adjustments or additional information!

You can reach me at susheel2339 @ gmail.com

. . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player