Python Documentation for Perplexity

Below is the documentation for integrating Reconify with Perplexity via Python PIP 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.

Python Integration

The easiest way to get started is to use the PIP module.

Install the module

pip install reconify

Import the module

from reconify import reconifyUniversalHandler

Initialize the module

Configure the instance of Reconify passing the Reconify API_KEY and APP_KEY created above.

reconifyUniversalHandler.config(  
appKey = "YOUR_APP_KEY",
apiKey = "YOUR_API_KEY",
)

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

input = {
   "model":"pplx-7b-chat",
   "messages":[
       {"role": "system", "content": "You are a comic"},
       {"role": "user", "content": "Tell a cat joke"},
   ]
}
start = reconifyUniversalHandler.getTimestamp()
response = requests.post("https://api.perplexity.ai/chat/completions", json=input, headers = {
   "accept":"application/json",
   "content-type":"application/json",
   "authorization": "Bearer YOUR_PERPLEXITY_KEY"
})
end = reconifyUniversalHandler.getTimestamp()
reconifyUniversalHandler.logChat(input, response.text, start, end)

Optional initialization parameters

You can optionally turn on "debug" mode by passing in "debug = True" in the method above. This will print debug messages to the console.

You can also disable image tracking, by passing in "trackImages = False" in the method.

reconifyUniversalHandler.config(  
appKey = "YOUR_APP_KEY",
apiKey = "YOUR_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.

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

The session ID is a simple string.

reconifyUniversalHandler.setSession('MySessionId');

Chat Example

import requests
from reconify import reconifyUniversalHandler

reconifyUniversalHandler.config(
 appKey = 'Your_App_Key',
 apiKey = 'Your_Api_Key'
)

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

input = {
   "model":"pplx-7b-chat",
   "messages":[
       {"role": "system", "content": "You are a comic"},
       {"role": "user", "content": "Tell a cat joke"},
   ]
}

start = reconifyUniversalHandler.getTimestamp()
response = requests.post("https://api.perplexity.ai/chat/completions", json=input, headers = {
   "accept":"application/json",
   "content-type":"application/json",
   "authorization": "Bearer YOUR_PERPLEXITY_KEY"
})
end = reconifyUniversalHandler.getTimestamp()

reconifyUniversalHandler.logChat(input, response.text, start, end)