Skip to main content

A package for sending data to the Reconify platform

Project description

Reconify PIP module

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 and the following foundational models using Amazon Bedrock: AI21 Jurassic, Anthropic Claude, Cohere Command, and Stability Stable Diffusion.

Support for additional actions and providers will be added.

Get started

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.

Install the module

pip install reconify

Integrate the module with OpenAI

Import the module

from reconify import reconifyOpenAIHandler

Initialize the module

Prior to initializing the Reconify module, make sure to import the OpenaAI module.

import openai
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, 
   appKey = 'Your_App_Key', 
   apiKey = 'Your_Api_Key'
)

This is all that is needed for a basic integration. The module takes care of sending the correct data to Reconify when you call openai.Completion.create or openai.ChatCompletion.create.

Optional Config Parameters

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:

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

Set a user

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.

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

Set a Session ID

The Session ID is an alphanumeric string.

reconifyOpenAIHandler.setSession('MySessionId')

Set Session Timeout

Set the session timeout in minutes to override the default

reconifyOpenAIHandler.setSessionTimeout(15)

Integrate the module with Amazon Bedrock Runtime

Import the module

from reconify import reconifyBedrockRuntimeHandler

Initialize the module

Prior to initializing the Reconify module, make sure to import the Amazon boto3 module.

import boto3
bedrock = boto3.client('bedrock-runtime')

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

reconifyBedrockRuntimeHandler.config(bedrock, 
   appKey = 'Your_App_Key', 
   apiKey = 'Your_Api_Key'
)

This is all that is needed for a basic integration. The module takes care of sending the correct data to Reconify when you call bedrock.invoke_model().

Response handling

When using the Reconify module, the response body from invoke_model will be converted from botocore.response.StreamingBody to JSON and saved in the response as parsedBody. See the examples below for more info.

Optional Config Parameters

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:

reconifyBedrockRuntimeHandler.config(bedrock, 
   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.

Set a user

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.

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

Set a Session ID

The Session ID is an alphanumeric string.

reconifyBedrockRuntimeHandler.setSession('MySessionId')

Set Session Timeout

Set the session timeout in minutes to override the default

reconifyBedrockRuntimeHandler.setSessionTimeout(15)

Examples with OpenAI

Chat Example

import os
import openai
from reconify import reconifyOpenAIHandler

openai.api_key = 'YOUR_OPENAI_KEY'

reconifyOpenAIHandler.config(openai, 'Your_App_Key', 'Your_Api_Key')

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

response = openai.ChatCompletion.create(
    model="gpt-3.5-turbo",
    messages=[
        {"role": "system", "content": "You are an expert on commedians."},
        {"role": "user", "content": "Tell a joke about cats"},
    ],
    temperature=0,
)

Completion Example

import os
import openai
from reconify import reconifyOpenAIHandler

openai.api_key = 'YOUR_OPENAI_KEY'

reconifyOpenAIHandler.config(openai, 'Your_App_Key', 'Your_Api_Key')

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

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

Image Example

import os
import openai
from reconify import reconifyOpenAIHandler

openai.api_key = 'YOUR_OPENAI_KEY'

reconifyOpenAIHandler.config(openai, 'Your_App_Key', 'Your_Api_Key')

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

response = openai.Image.create(
   prompt = "a cat on the moon",
   n = 1,
   size = "256x256"
   response_format = "url"
)

Examples with Amazon Bedrock Runtime

Anthropic Claude example

import boto3
from reconify import reconifyBedrockRuntimeHandler

bedrock = boto3.client('bedrock-runtime')

reconifyBedrockRuntimeHandler.config(bedrock, 'Your_App_Key', 'Your_Api_Key')

reconifyOpenAIHandler.setUser({
   "userId": "12345",
   "firstName": "Jane",
   "lastName": "Smith"
})

response = bedrock.invoke_model(
    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\"}"
)

#The botocore.response.StreamingBody object will be converted to JSON and saved in parsedBody
print(response.get("parsedBody"))

Stable Diffusion image example

import boto3
from reconify import reconifyBedrockRuntimeHandler

bedrock = boto3.client('bedrock-runtime')

reconifyBedrockRuntimeHandler.config(bedrock, 'Your_App_Key', 'Your_Api_Key')

reconifyOpenAIHandler.setUser({
   "userId": "12345",
   "firstName": "Jane",
   "lastName": "Smith"
})

response = bedrock.invoke_model(
    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}"
)
#The botocore.response.StreamingBody object will be converted to JSON and saved in parsedBody
#The following will print out the image result in JSON base64
print(response.get("parsedBody"))

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

reconify-1.0.4.tar.gz (6.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

reconify-1.0.4-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file reconify-1.0.4.tar.gz.

File metadata

  • Download URL: reconify-1.0.4.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.7.3

File hashes

Hashes for reconify-1.0.4.tar.gz
Algorithm Hash digest
SHA256 c3707d543ad1d09964c07896b3947cb4e889149f53d93dd68a30be5de89258f0
MD5 4305d8a84594d941875f2c82b56c1f17
BLAKE2b-256 e93ab88f70407fce2d633d01900750a29c1dc1cc263ca303f5b23db7dd774930

See more details on using hashes here.

File details

Details for the file reconify-1.0.4-py3-none-any.whl.

File metadata

  • Download URL: reconify-1.0.4-py3-none-any.whl
  • Upload date:
  • Size: 7.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.7.3

File hashes

Hashes for reconify-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 2030d68849853181f2bdcb180d6c0cb7808d3a8e3048065c39ec3227e314e464
MD5 64fbb8117c4048706585b98ed02a0a07
BLAKE2b-256 e041cca86aae6ad92141f72ac1e7cbaf4783df423aa87102d40a4cdf857f8dc5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page