Node Documentation for OpenAI Legacy SDK

Below is the documentation for integrating Reconify with OpenAI's Legacy SDK (prior to Nov 2023) via Node NPM module. For integration, with the latest version, please view the current Node integration docs.

Currently we support Chat, Completion, and Image actions on OpenAI.

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 {reconifyOpenAILegacyV3Handler} from 'reconify';

Initialize the module

Initialize the module passing in the openai object and the keys created above.

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

This is all that is needed, and the NPM takes care of the rest when you call either openai.createCompletion or openai.createChatCompletion.

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 = reconifyOpenAILegacyV3Handler(openai, {
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 { Configuration, OpenAIApi } from "openai";
import { reconifyOpenAILegacyV3Handler } from 'reconify';

const configuration = new Configuration({
  apiKey: process.env.OPENAI_API_KEY,
});

const openai = new OpenAIApi(configuration);

const reconify = reconifyOpenAILegacyV3Handler(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.createChatCompletion({
  model: "gpt-3.5-turbo",
  messages: [
  {role: "system", content: "you are an expert on commedians"},
  {role: "user", content: "tell a joke about cats like eddie murphy"}
  ],
});

Completion Example

import { Configuration, OpenAIApi } from "openai";
import { reconifyOpenAILegacyV3Handler } from 'reconify';

const configuration = new Configuration({
  apiKey: process.env.OPENAI_API_KEY,
});

const openai = new OpenAIApi(configuration);

const reconify = reconifyOpenAILegacyV3Handler(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.createCompletion({
  model: "text-davinci-003",
  prompt: "write a haiku about cats",
  max_tokens: 100,
  temperature: 0,
});

Image Example

import { Configuration, OpenAIApi } from "openai";
import { reconifyOpenAILegacyV3Handler } from 'reconify';

const configuration = new Configuration({
  apiKey: process.env.OPENAI_API_KEY,
});

const openai = new OpenAIApi(configuration);

const reconify = reconifyOpenAILegacyV3Handler(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.createImage({
  prompt: "a cat on the moon",
  n: 1,
  size: "256x256",
  response_format: "url",
});