Python Documentation for OpenAI

Below is the documentation for integrating Reconify with OpenAI via Python PIP module.

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.

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 reconifyOpenAIHandler

Initialize the module

Prior to initializing the Reconify module, make sure to import and initialize the OpenAI module

from openai import OpenAI
openai_client = OpenAI(api_key = "YOUR_OPENAI_KEY")

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

reconifyOpenAIHandler.config(openai_client,  
appKey = "YOUR_APP_KEY",
apiKey = "YOUR_API_KEY",
)

This is all that is needed for the basic integration. The module takes care of the rest when you call either openai.Completion.create or openai.ChatCompletion.create.

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.

reconifyOpenAIHandler.config(openai_client,  
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.

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

The session ID is a simple string.

reconifyOpenAIHandler.setSession('MySessionId');

Chat Example

from openai import OpenAI
from reconify import reconifyOpenAIHandler

openai_client = OpenAI(api_key = "YOUR_OPENAI_KEY")

reconifyOpenAIHandler.config(openai_client,
 appKey = 'Your_App_Key',
 apiKey = 'Your_Api_Key'
)

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

response = openai_client.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"},
 ],
 temperature=0,
)

Completion Example

from openai import OpenAI
from reconify import reconifyOpenAIHandler

openai_client = OpenAI(api_key = "YOUR_OPENAI_KEY")

reconifyOpenAIHandler.config(openai_client,
 appKey = 'Your_App_Key',
 apiKey = 'Your_Api_Key'
)

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

response = openai_client.completions.create(
 model="text-davinci-003",
 prompt="write a haiku about cats",
 max_tokens: 100,
 temperature=0,
)

Image Example

from openai import OpenAI
from reconify import reconifyOpenAIHandler

openai_client = OpenAI(api_key = "YOUR_OPENAI_KEY")

reconifyOpenAIHandler.config(openai_client,
 appKey = 'Your_App_Key',
 apiKey = 'Your_Api_Key'
)

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

response = openai_client.images.generate(
  model = "dall-e-3"
 prompt = "a cat on the moon",
 n = 1,
 size = "1024x1024",
 response_format = "url"
)