Node Documentation for Perplexity

Below is the documentation for integrating Reconify with Perplexity via Node NPM module.

Currently we support Chat actions on Perplexity.

Get started - Create an account

The first step is to create an account at app.reconify.com.

Generate API and APP Keys

In the Reconify console, add an Application to your account. This will generate both an API_KEY and an APP_KEY which will be used in the code below to send data to Reconify.

Node Integration

The easiest way to integrate in Node.js is with the NPM module.

Install the NPM module

npm install reconify --save

Import the module

import {reconifyUniversalHandler} from 'reconify';

Initialize the module

Prior to initializing the Reconify module, make sure to import and initialize the API NPM and the Perplexity SDK module.

import { api } from "api";
const sdk = api('@pplx/v0#b2wdhb1klq5dn1d6');
sdk.auth(process.env.PERPLEXITY_API_KEY);

Initialize the Reconify module passing in the keys created above.

const reconify = reconifyUniversalHandler({
appKey: process.env.RECONIFY_APP_KEY,
apiKey: process.env.RECONIFY_API_KEY,
})

After making a call to the Perplexity SDK API, send the input parameters and response data to Reconify, along with the start and end timestamps.

const start = reconify.getTimestamp();
const input = {
  model: 'pplx-7b-chat',
  messages: [
     { role: "system", content: "You are a comic"},
     { role: 'user', content: 'Tell me a cat joke.'}
  ]
}
const response = await sdk.post_chat_completions(input);
const end = reconify.getTimestamp();
reconify.logChat(input, response.data, start, end);

Optional initialization parameters

You can optionally turn on "debug" mode by passing in "debug: true" in the JSON above. This will print debug messages to the console.

You can also disable image tracking, by passing in "trackImages : false" in the JSON.

const reconify = reconifyUniversalHandler({
appKey: process.env.RECONIFY_APP_KEY,
apiKey: process.env.RECONIFY_API_KEY,
debug: true,
})

Optional methods

You can optionally pass in a user object or session ID to be used in the analytics reporting. The session ID will be used to group interactions together in the same session transcript.

The user object should include a unique userId, the other fields are optional.

reconify.setUser ({
  "userId": "123",
  "isAuthenticated": 1,
  "firstName": "Francis",
  "lastName": "Smith",
  "email": "",
  "phone": "",
  "gender": "female"
});

The session ID is a simple string.

reconify.setSession('MySessionId');

Chat Example

import { api } from 'api';
import { reconifyUniversalHandler } from 'reconify';

const sdk = api('@pplx/v0#b2wdhb1klq5dn1d6')
sdk.auth(process.env.PERPLEXITY_API_KEY);

const reconify = reconifyUniversalHandler({
  appKey: process.env.RECONIFY_APP_KEY,
  apiKey: process.env.RECONIFY_API_KEY,
});

reconify.setUser({
  userId: "12345",
  firstName: "Jim",
  lastName: "Stand",
});

const start = reconify.getTimestamp();
const input = {
  model: 'pplx-7b-chat',
  messages: [
     { role: "system", content: "You are a comic"},
     { role: 'user', content: 'Tell me a cat joke.'}
  ]
}
const response = await sdk.post_chat_completions(input);
const end = reconify.getTimestamp();

reconify.logChat(input, response.data, start, end);