danubeRecommendation - Examples

In the following, example calls and the according return values using the danubeRecommendation method of a DanubeClient instance are shown.

You can also download and try a set of working demo examples for each danube.ai service using the SDK here: https://gitlab.com/danube.ai/sdk

const { DanubeClient } = require('danube-sdk'); 

// Initialize a DanubeClient with your API key.
const danubeClient = new DanubeClient(
  'my-api-key',
);

async function runTest() {
  // Session 1

  // Step 1
  const result_1_1 = await danubeClient.danubeRecommendation(
    JSON.stringify([{ page: 'Home' }]),
    3,
  );

  // Step 2
  const result_1_2 = await danubeClient.danubeRecommendation(
    JSON.stringify([{ page: 'Home' }, { page: 'About' }]),
    3,
  );

  // Step 3
  const result_1_3 = await danubeClient.danubeRecommendation(
    JSON.stringify([{ page: 'Home' }, { page: 'About' }, { page: 'Pricing' }]),
    3,
  );


  // Session 2

  // Step 1
  const result_2_1 = await danubeClient.danubeRecommendation(
    JSON.stringify([{ page: 'Home' }]),
    3,
  );

  // Step 2
  const result_2_2 = await danubeClient.danubeRecommendation(
    JSON.stringify([{ page: 'Home' }, { page: 'Pricing' }]),
    3,
  );

  // Step 3
  const result_2_3 = await danubeClient.danubeRecommendation(
    JSON.stringify([{ page: 'Home' }, { page: 'Pricing' }, { page: 'Imprint' }]),
    3,
  );


  // Session 3

  // Step 1
  const result_3_1 = await danubeClient.danubeRecommendation(
    JSON.stringify([{ page: 'Home' }]),
    3,
  );
}

runTest();

console.log('Session 1:');
console.log('Step 1:', result_1_1);
console.log('Step 2:', result_1_2);
console.log('Step 3:', result_1_3);

console.log('Session 2:');
console.log('Step 1:', result_2_1);
console.log('Step 2:', result_2_2);
console.log('Step 3:', result_2_3);

console.log('Session 3:');
console.log('Step 1:', result_3_1);

/*
Session 1:
Step 1: { correlatedData: '[]' }
Step 2: { correlatedData: '[]' }
Step 3: { correlatedData: '[]' }

Session 2:
Step 1: { correlatedData: '[{"page":"Pricing","_danubeScore":4},{"page":"About","_danubeScore":0}]' }
Step 2: { correlatedData: '[{"page":"About","_danubeScore":0}]' }
Step 3: { correlatedData: '[{"page":"About","_danubeScore":0}]' }

Session 3:
Step 1: { correlatedData: '[{"page":"Pricing","_danubeScore":6},{"page":"Imprint","_danubeScore":3.785370547493044},{"page":"About","_danubeScore":0.13677942320303804}]' }
*/