The Reconify module is used for sending data to the Reconify platform at www.reconify.com.
Currently the module supports processing and analyzing Chats, Completions, and Images from:
- OpenAI
- Amazon Bedrock (Amazon Titan, AI21 Jurassic, Anthropic Claude, Cohere Command, Meta Llama 2, Mistral, and Stability Stable Diffusion)
- Anthropic
- Cohere
- Google Gemini
- Mistral
- Perplexity
Support for additional actions and providers will be added.
The first step is to create an account at app.reconify.com.
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.
npm install reconify --save
The following instructions are for OpenAI's Node NPM v4 or later (released in Nov 2023). For earlier versions of OpenAI's NPM, follow the legacy instructions
import {reconifyOpenAIHandler} from 'reconify';
Prior to initializing the Reconify module, create an instance of OpenAI which will be passed to the module.
const openai = new OpenAI({
apiKey: process.env.OPENAI_API_KEY,
});
Create the instance of Reconify passing the OpenAi instance along with the Reconify API_KEY and APP_KEY created above.
const reconify = reconifyOpenAIHandler(openai, {
appKey: process.env.RECONIFY_APP_KEY,
apiKey: process.env.RECONIFY_API_KEY,
});
This is all that is needed for a basic integration. The module takes care of sending the correct data to Reconify.
There are additional optional parameters that can be passed in to the handler.
- debug: (default false) Enable/Disable console logging
- trackImages: (default true) Turn on/off tracking of createImage
For example:
const reconify = reconifyOpenAIHandler(openai, {
appKey: process.env.RECONIFY_APP_KEY,
apiKey: process.env.RECONIFY_API_KEY,
debug: true
});
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 JSON should include a unique userId, all the other fields are optional. Without a unique userId, each user will be treated as a new user.
reconify.setUser ({
"userId": "ABC123",
"isAuthenticated": 1,
"firstName": "Francis",
"lastName": "Smith",
"email": "",
"phone": "",
"gender": "female"
});
The Session ID is an alphanumeric string.
reconify.setSession('MySessionId');
Set the session timeout in minutes to override the default
reconify.setSessionTimeout(15);
import {reconifyBedrockRuntimeHandler} from 'reconify';
import {BedrockRuntimeClient, InvokeModelCommand} from "@aws-sdk/client-bedrock-runtime";
Create an instance of the BedrockRuntimeClient.
const client = new BedrockRuntimeClient({
region: "us-west-2"
});
Create the instance of Reconify with the Reconify API_KEY and APP_KEY created above.
const reconify = reconifyBedrockRuntimeHandler({
appKey: process.env.RECONIFY_APP_KEY,
apiKey: process.env.RECONIFY_API_KEY,
});
client.middlewareStack.use(reconify.plugin());
This is all that is needed for a basic integration. The module takes care of sending the correct data to Reconify.
There are additional optional parameters that can be passed in to the handler.
- debug: (default false) Enable/Disable console logging
- trackImages: (default true) Turn on/off tracking of images
For example:
const reconify = reconifyBedrockRuntimeHandler({
appKey: process.env.RECONIFY_APP_KEY,
apiKey: process.env.RECONIFY_API_KEY,
debug: true
});
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 JSON should include a unique userId, all the other fields are optional. Without a unique userId, each user will be treated as a new user.
reconify.setUser ({
"userId": "ABC123",
"isAuthenticated": 1,
"firstName": "Francis",
"lastName": "Smith",
"email": "",
"phone": "",
"gender": "female"
});
The Session ID is an alphanumeric string.
reconify.setSession('MySessionId');
Set the session timeout in minutes to override the default
reconify.setSessionTimeout(15);
See Examples with Amazon Bedrock Runtime
The following instructions are for Anthropic's Node NPM.
import {reconifyAnthropicHandler} from 'reconify';
Prior to initializing the Reconify module, create an instance of Anthropic which will be passed to the module.
const anthropic = new Anthropic({
apiKey: process.env.ANTHROPIC_API_KEY,
});
Create the instance of Reconify passing the Anthropic instance along with the Reconify API_KEY and APP_KEY created above.
const reconify = reconifyAnthropicHandler(anthropic, {
appKey: process.env.RECONIFY_APP_KEY,
apiKey: process.env.RECONIFY_API_KEY,
});
This is all that is needed for a basic integration. The module takes care of sending the correct data to Reconify.
There are additional optional parameters that can be passed in to the handler.
- debug: (default false) Enable/Disable console logging
- trackImages: (default true) Turn on/off tracking of createImage
For example:
const reconify = reconifyAnthropicHandler(anthropic, {
appKey: process.env.RECONIFY_APP_KEY,
apiKey: process.env.RECONIFY_API_KEY,
debug: true
});
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 JSON should include a unique userId, all the other fields are optional. Without a unique userId, each user will be treated as a new user.
reconify.setUser ({
"userId": "ABC123",
"isAuthenticated": 1,
"firstName": "Francis",
"lastName": "Smith",
"email": "",
"phone": "",
"gender": "female"
});
The Session ID is an alphanumeric string.
reconify.setSession('MySessionId');
Set the session timeout in minutes to override the default
reconify.setSessionTimeout(15);
The following instructions are for Cohere's Node NPM.
import {reconifyCohereHandler} from 'reconify';
Prior to initializing the Reconify module, create an instance of Cohere which will be passed to the module.
const cohere = new CohereClient({
token: process.env.COHERE_API_KEY,
});
Create the instance of Reconify passing the Cohere instance along with the Reconify API_KEY and APP_KEY created above.
const reconify = reconifyCohereHandler(cohere, {
appKey: process.env.RECONIFY_APP_KEY,
apiKey: process.env.RECONIFY_API_KEY,
});
This is all that is needed for a basic integration. The module takes care of sending the correct data to Reconify.
There are additional optional parameters that can be passed in to the handler.
- debug: (default false) Enable/Disable console logging
- trackImages: (default true) Turn on/off tracking of createImage
For example:
const reconify = reconifyCohereHandler(cohere, {
appKey: process.env.RECONIFY_APP_KEY,
apiKey: process.env.RECONIFY_API_KEY,
debug: true
});
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 JSON should include a unique userId, all the other fields are optional. Without a unique userId, each user will be treated as a new user.
reconify.setUser ({
"userId": "ABC123",
"isAuthenticated": 1,
"firstName": "Francis",
"lastName": "Smith",
"email": "",
"phone": "",
"gender": "female"
});
The Session ID is an alphanumeric string.
reconify.setSession('MySessionId');
Set the session timeout in minutes to override the default
reconify.setSessionTimeout(15);
The following instructions are for Google's Node NPM.
import {reconifyGeminiHandler} from 'reconify';
Prior to initializing the Reconify module, create an instance of Google Gemini which will be passed to the module.
import { GoogleGenerativeAI } from '@google/generative-ai';
const genAI = new GoogleGenerativeAI(process.env.GEMINI_API_KEY);
Create the instance of Reconify passing the Gemini instance along with the Reconify API_KEY and APP_KEY created above.
const reconify = reconifyGeminiHandler(genAI, {
appKey: process.env.RECONIFY_APP_KEY,
apiKey: process.env.RECONIFY_API_KEY,
});
This is all that is needed for a basic integration. The module takes care of sending the correct data to Reconify.
There are additional optional parameters that can be passed in to the handler.
- debug: (default false) Enable/Disable console logging
- trackImages: (default true) Turn on/off tracking of createImage
For example:
const reconify = reconifyGeminiHandler(genAI, {
appKey: process.env.RECONIFY_APP_KEY,
apiKey: process.env.RECONIFY_API_KEY,
debug: true
});
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 JSON should include a unique userId, all the other fields are optional. Without a unique userId, each user will be treated as a new user.
reconify.setUser ({
"userId": "ABC123",
"isAuthenticated": 1,
"firstName": "Francis",
"lastName": "Smith",
"email": "",
"phone": "",
"gender": "female"
});
The Session ID is an alphanumeric string.
reconify.setSession('MySessionId');
Set the session timeout in minutes to override the default
reconify.setSessionTimeout(15);
See Examples with Google Gemini
The following instructions are for Mistral's Node NPM.
import {reconifyMistralHandler} from 'reconify';
Prior to initializing the Reconify module, create an instance of the Mistral Client which will be passed to the module.
import { MistralClient } from '@mistralai/mistralai';
const client = new MistralClient(process.env.MISTRAL_API_KEY);
Create the instance of Reconify passing the Mistral instance along with the Reconify API_KEY and APP_KEY created above.
const reconify = reconifyMistralHandler(client, {
appKey: process.env.RECONIFY_APP_KEY,
apiKey: process.env.RECONIFY_API_KEY,
});
This is all that is needed for a basic integration. The module takes care of sending the correct data to Reconify.
There are additional optional parameters that can be passed in to the handler.
- debug: (default false) Enable/Disable console logging
- trackImages: (default true) Turn on/off tracking of createImage
For example:
const reconify = reconifyMistralHandler(genAI, {
appKey: process.env.RECONIFY_APP_KEY,
apiKey: process.env.RECONIFY_API_KEY,
debug: true
});
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 JSON should include a unique userId, all the other fields are optional. Without a unique userId, each user will be treated as a new user.
reconify.setUser ({
"userId": "ABC123",
"isAuthenticated": 1,
"firstName": "Francis",
"lastName": "Smith",
"email": "",
"phone": "",
"gender": "female"
});
The Session ID is an alphanumeric string.
reconify.setSession('MySessionId');
Set the session timeout in minutes to override the default
reconify.setSessionTimeout(15);
The following instructions are for Perplexity with the API NPM.
import {reconifyUniversalHandler} from 'reconify';
Prior to initializing the Reconify module, create an instance of the API SDK for Perplexity.
import { api } from 'api';
const sdk = api('@pplx/v0#b2wdhb1klq5dn1d6')
sdk.auth(process.env.PERPLEXITY_API_KEY);
Create the instance of Reconify passing the Reconify API_KEY and APP_KEY 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 time stamps.
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);
There are additional optional parameters that can be passed in to the handler.
- debug: (default false) Enable/Disable console logging
- trackImages: (default true) Turn on/off tracking of createImage
For example:
const reconify = reconifyUniversalHandler(genAI, {
appKey: process.env.RECONIFY_APP_KEY,
apiKey: process.env.RECONIFY_API_KEY,
debug: true
});
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 JSON should include a unique userId, all the other fields are optional. Without a unique userId, each user will be treated as a new user.
reconify.setUser ({
"userId": "ABC123",
"isAuthenticated": 1,
"firstName": "Francis",
"lastName": "Smith",
"email": "",
"phone": "",
"gender": "female"
});
The Session ID is an alphanumeric string.
reconify.setSession('MySessionId');
Set the session timeout in minutes to override the default
reconify.setSessionTimeout(15);
import { OpenAI } from "openai";
import { reconifyOpenAIHandler } from 'reconify';
const openai = new OpenAI({
apiKey: process.env.OPENAI_API_KEY,
});
const reconify = reconifyOpenAIHandler(openai, {
appKey: process.env.RECONIFY_APP_KEY,
apiKey: process.env.RECONIFY_API_KEY,
});
reconify.setUser({
userId: "12345",
isAuthenticated: 1,
firstName: "Jim",
lastName: "Stand",
gender: "male"
});
const completion = await openai.chat.completions.create({
model: "gpt-3.5-turbo",
messages: [
{role: "system", content: "you are an expert on comedians"},
{role: "user", content: "tell a joke about cats like Jerry Seinfeld"}
],
});
import { OpenAI } from "openai";
import { reconifyOpenAIHandler } from 'reconify';
const openai = new OpenAI({
apiKey: process.env.OPENAI_API_KEY,
});
const reconify = reconifyOpenAIHandler(openai, {
appKey: process.env.RECONIFY_APP_KEY,
apiKey: process.env.RECONIFY_API_KEY,
});
reconify.setUser({
userId: "12345",
isAuthenticated: 1,
firstName: "Jim",
lastName: "Stand",
gender: "male"
});
const completion = await openai.completions.create({
model: "text-davinci-003",
prompt: "write a haiku about cats",
max_tokens: 100,
temperature: 0,
});
import { OpenAI } from "openai";
import { reconifyOpenAIHandler } from 'reconify';
const openai = new OpenAI({
apiKey: process.env.OPENAI_API_KEY,
});
const reconify = reconifyOpenAIHandler(openai, {
appKey: process.env.RECONIFY_APP_KEY,
apiKey: process.env.RECONIFY_API_KEY,
});
reconify.setUser({
userId: "12345",
isAuthenticated: 1,
firstName: "Jim",
lastName: "Stand",
gender: "male"
});
const result = await openai.images.generate({
model: "dall-e-3"
prompt: "a cat on the moon",
n: 1,
size: "1024x1024",
response_format: "url"
});
import {BedrockRuntimeClient, InvokeModelCommand} from "@aws-sdk/client-bedrock-runtime";
import {reconifyBedrockRuntimeHandler} from 'reconify';
const client = new BedrockRuntimeClient({
region: "us-west-2",
credentials: {
accessKeyId: process.env.AWS_ACCESS_KEY,
secretAccessKey: process.env.AWS_SECRET_KEY
}
})
const reconify = reconifyBedrockRuntimeHandler({
appKey: process.env.RECONIFY_APP_KEY,
apiKey: process.env.RECONIFY_API_KEY,
});
client.middlewareStack.use(reconify.plugin());
reconify.setUser({
userId: "12345",
firstName: "Jane",
lastName: "Smith"
});
const command = new InvokeModelCommand({
modelId: "anthropic.claude-instant-v1",
contentType: "application/json",
accept: "application/json",
body: "{\"prompt\":\"\\n\\nHuman: Tell a cat joke.\\n\\nAssistant:\",\"max_tokens_to_sample\":300,\"temperature\":1,\"top_k\":250,\"top_p\":0.999,\"stop_sequences\":[\"\\n\\nHuman:\"],\"anthropic_version\":\"bedrock-2023-05-31\"}"
});
const results = await client.send(command)
import {BedrockRuntimeClient, InvokeModelCommand} from "@aws-sdk/client-bedrock-runtime";
import {reconifyBedrockRuntimeHandler} from 'reconify';
const client = new BedrockRuntimeClient({
region: "us-west-2",
credentials: {
accessKeyId: process.env.AWS_ACCESS_KEY,
secretAccessKey: process.env.AWS_SECRET_KEY
}
})
const reconify = reconifyBedrockRuntimeHandler({
appKey: process.env.RECONIFY_APP_KEY,
apiKey: process.env.RECONIFY_API_KEY,
});
client.middlewareStack.use(reconify.plugin());
reconify.setUser({
userId: "12345",
firstName: "Jane",
lastName: "Smith"
});
const command = new InvokeModelCommand({
modelId: "stability.stable-diffusion-xl-v0",
contentType: "application/json",
accept: "application/json",
body: "{\"text_prompts\":[{\"text\":\"a cat drinking boba tea\"}],\"cfg_scale\":10,\"seed\":0,\"steps\":50}"
});
const results = await client.send(command)
import Anthropic from '@anthropic-ai/sdk';
import { reconifyAnthropicHandler } from 'reconify';
const anthropic = new Anthropic({
apiKey: process.env.ANTHROPIC_API_KEY,
});
const reconify = reconifyAnthropicHandler(anthropic, {
appKey: process.env.RECONIFY_APP_KEY,
apiKey: process.env.RECONIFY_API_KEY,
});
reconify.setUser({
userId: "12345",
firstName: "Jane",
lastName: "Smith"
});
const chat = await anthropic.messages.create({
model: "claude-2.1",
max_tokens: 300,
messages: [
{role: "user", content: "Tell me a cat joke"}
]
});
import Anthropic from '@anthropic-ai/sdk';
import { reconifyAnthropicHandler } from 'reconify';
const anthropic = new Anthropic({
apiKey: process.env.ANTHROPIC_API_KEY,
});
const reconify = reconifyAnthropicHandler(anthropic, {
appKey: process.env.RECONIFY_APP_KEY,
apiKey: process.env.RECONIFY_API_KEY,
});
reconify.setUser({
userId: "12345",
firstName: "Jane",
lastName: "Smith"
});
const completion = await anthropic.completions.create({
model: "claude-2",
max_tokens_to_sample: 300,
prompt: `${Anthropic.HUMAN_PROMPT} Tell me a cat joke${Anthropic.AI_PROMPT}`
});
import { CohereClient } from "cohere-ai";
import { reconifyCohereHandler } from 'reconify';
const cohere = new CohereClient({
token: process.env.COHERE_API_KEY,
});
const reconify = reconifyCohereHandler(cohere, {
appKey: process.env.RECONIFY_APP_KEY,
apiKey: process.env.RECONIFY_API_KEY,
});
reconify.setUser({
userId: "12345",
firstName: "Jane",
lastName: "Smith"
});
const completion = await cohere.chat({
model: "command",
message: "Tell me a cat joke"
});
import { CohereClient } from "cohere-ai";
import { reconifyCohereHandler } from 'reconify';
const cohere = new CohereClient({
token: process.env.COHERE_API_KEY,
});
const reconify = reconifyCohereHandler(cohere, {
appKey: process.env.RECONIFY_APP_KEY,
apiKey: process.env.RECONIFY_API_KEY,
});
reconify.setUser({
userId: "12345",
firstName: "Jane",
lastName: "Smith"
});
const completion = await cohere.generate({
model: "command",
message: "Write a cat haiku",
max_tokens: 300
});
import { GoogleGenerativeAI } from '@google/generative-ai';
import { reconifyGeminiHandler } from 'reconify';
const genAI = new GoogleGenerativeAI(process.env.GEMINI_API_KEY);
const reconify = reconifyGeminiHandler(genAI, {
appKey: process.env.RECONIFY_APP_KEY,
apiKey: process.env.RECONIFY_API_KEY,
});
reconify.setUser({
userId: "12345",
firstName: "Jane",
lastName: "Smith"
});
const model = genAI.getGenerativeModel({ model: "gemini-pro" });
const result = await model.generateContent("Tell me a cat joke");
const response = await result.response;
const text = response.text();
import { GoogleGenerativeAI } from '@google/generative-ai';
import { reconifyGeminiHandler } from 'reconify';
import * as fs from 'fs';
const genAI = new GoogleGenerativeAI(process.env.GEMINI_API_KEY);
const reconify = reconifyGeminiHandler(genAI, {
appKey: process.env.RECONIFY_APP_KEY,
apiKey: process.env.RECONIFY_API_KEY,
});
reconify.setUser({
userId: "12345",
firstName: "Jane",
lastName: "Smith"
});
const fileToGenerativePart = (path, mimeType) => {
return {
inlineData: {
data: Buffer.from(fs.readFileSync(path)).toString("base64"),
mimeType
},
};
}
const model = genAI.getGenerativeModel({ model: "gemini-pro-vision" });
const imageParts = [fileToGenerativePart("holiday-cat.jpg", "image/jpeg")];
const result = await model.generateContent(["Describe this photo", ...imageParts]);
const response = await result.response;
const text = response.text();
import { GoogleGenerativeAI } from '@google/generative-ai';
import { reconifyGeminiHandler } from 'reconify';
const genAI = new GoogleGenerativeAI(process.env.GEMINI_API_KEY);
const reconify = reconifyGeminiHandler(genAI, {
appKey: process.env.RECONIFY_APP_KEY,
apiKey: process.env.RECONIFY_API_KEY,
});
reconify.setUser({
userId: "12345",
firstName: "Jane",
lastName: "Smith"
});
const model = genAI.getGenerativeModel({ model: "gemini-pro" });
const chat = model.startChat({
history: [
{ role: "user", parts: "I have a tuxedo cat and a calico cat"},
{ role: "model", parts: "How can I help?"}
],
generationConfig: {
maxOutputTokens: 200
}
})
const result = await chat.sendMessage("How many colors are my cats?")
const response = await result.response;
const text = response.text();
import { MistralClient } from '@mistralai/mistralai';
import { reconifyMistralHandler } from 'reconify';
const client = new MistralClient(process.env.MISTRAL_API_KEY);
const reconify = reconifyMistralHandler(client, {
appKey: process.env.RECONIFY_APP_KEY,
apiKey: process.env.RECONIFY_API_KEY,
});
reconify.setUser({
userId: "12345",
firstName: "Jane",
lastName: "Smith"
});
const response = await client.chat({
model: 'mistral-tiny',
messages: [
{ role: 'user', content: 'Tell me a cat joke.'}
]
});
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: "Jane",
lastName: "Smith"
});
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);