Python Documentation for Mistral

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

Currently we support Chat actions with Mistral.

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 reconifyMistralHandler

Initialize the module

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

from mistralai.client import MistralClient
mistral_client = MistralClient(api_key = "YOUR_MISTRAL_KEY")

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

reconifyMistralHandler.config(mistral_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 mistral_client.chat.

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.

reconifyMistralHandler.config(mistral_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.

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

The session ID is a simple string.

reconifyMistralHandler.setSession('MySessionId');

Chat Example

from mistralai.client import MistralClient
from mistralai.models.chat_completion import ChatMessage
from reconify import reconifyMistralHandler

mistral_client = MistralClient(api_key = "YOUR_MISTRAL_KEY")

reconifyMistralHandler.config(mistral_client,
 appKey = 'Your_App_Key',
 apiKey = 'Your_Api_Key'
)

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

response = mistral_client.chat(
 model="mistral-tiny",
 messages=[
   {"role": "system", "content": "You are a stand up comic"},
   {"role": "user", "content": "Tell a joke about cats"},
 ],
 temperature=0,
)