Open AI
To get started collecting events in your application using OpenAI, our SDKs have methods to automate AI event collection with a single line of code.
Firstly, ensure that Trubrics is imported & initialised in your app:
API key
Your trubrics API key is unique to your project. Login to Trubrics, and copy your project API key from the settings
page. This is a write only API key that allows you to push events.
Now start tacking prompts and generations from OpenAI by adding a single line to your OpenAI initializer:
Advanced tracking
While this is all you need to start tracking Open AI messages with Trubrics, enhanced Trubrics features such as Threads will require a tool to be set in the openai.chat.completions.create() request. This tool will only serve the purpose of transmitting metadata to Trubrics, and will be removed from the request to Open AI.
This tool must be named "Trubrics parameters" and be structured as below. It can be added to an existing list of tools, or as a single tool.
We recommend including a thread ID and a user ID if a user has not already been identified.
const completion = await openai.chat.completions.create({
model: "gpt-4o-mini",
messages=[
{"role": "user", "content": "Who won the world series in 2020?"},
],
tools: [
{
"type": "function",
"function": {
"name": "Trubrics parameters",
"parameters": {
"thread_id": "your-thread-id",
"user_id": "your-user-id"
}
}
}
]
});