Python library for tracing, logging, and detecting problems with AI Agents
Project description
quotientai
Overview
quotientai is an SDK and CLI for logging data to Quotient, and running hallucination and document attribution detections for retrieval and search-augmented AI systems.
Installation
pip install quotientai
Usage
Create an API key on Quotient and set it as an environment variable called QUOTIENT_API_KEY. Then follow the examples below or see our docs for a more comprehensive walkthrough.
Send your first log and detect hallucinations. Run the code below and see your Logs and Detections on your Quotient Dashboard.
from quotientai import QuotientAI
from quotientai.types import DetectionType
quotient = QuotientAI()
quotient.logger.init(
# Required
app_name="my-app",
environment="dev",
# dynamic labels for slicing/dicing analytics e.g. by customer, feature, etc
tags={"model": "gpt-4o", "feature": "customer-support"},
detections=[DetectionType.HALLUCINATION, DetectionType.DOCUMENT_RELEVANCY],
detection_sample_rate=1.0,
)
log_id = quotient.log(
user_query="How do I cook a goose?",
model_output="The capital of France is Paris",
documents=["Here is an excellent goose recipe..."]
)
print(log_id)
You can also use the async client if you need to create logs asynchronously.
from quotientai import AsyncQuotientAI
from quotientai.types import DetectionType
import asyncio
quotient = AsyncQuotientAI()
quotient.logger.init(
# Required
app_name="my-app",
environment="dev",
# dynamic labels for slicing/dicing analytics e.g. by customer, feature, etc
tags={"model": "gpt-4o", "feature": "customer-support"},
detections=[DetectionType.HALLUCINATION, DetectionType.DOCUMENT_RELEVANCY],
detection_sample_rate=1.0,
)
async def main():
# Mock retrieved documents
retrieved_documents = [{"page_content": "Sample document"}]
log_id = await quotient.log(
user_query="Sample input",
model_output="Sample output",
# Page content from Documents from your retriever used to generate the model output
documents=[doc["page_content"] for doc in retrieved_documents],
# Message history from your chat history
message_history=[
{"role": "system", "content": "You are an expert on geography."},
{"role": "user", "content": "What is the capital of France?"},
{"role": "assistant", "content": "The capital of France is Paris"},
],
# Instructions for the model to follow
instructions=[
"You are a helpful assistant that answers questions about the world.",
"Answer the question in a concise manner. If you are not sure, say 'I don't know'.",
],
# Tags can be overridden at log time
tags={"model": "gpt-4o-mini", "feature": "customer-support"},
)
print(log_id)
# Run the async function
asyncio.run(main())
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file quotientai-0.4.4.tar.gz.
File metadata
- Download URL: quotientai-0.4.4.tar.gz
- Upload date:
- Size: 31.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5041fe17923f702d7c72df7c34466921a4f9b9ed68930085a0411dbf3a101211
|
|
| MD5 |
27e08a3cf4c88d1effc30d77c12844f3
|
|
| BLAKE2b-256 |
f268b4f792fcb1c0bc6a2262d3a8a9af9420f383a99ee682545df7344dd279cc
|
File details
Details for the file quotientai-0.4.4-py3-none-any.whl.
File metadata
- Download URL: quotientai-0.4.4-py3-none-any.whl
- Upload date:
- Size: 43.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a03f45704249d35e39139c02088d2d8265b6238183a774ea3d5c753ae72f827c
|
|
| MD5 |
1bc64d2dad45567b4bc147728789ee23
|
|
| BLAKE2b-256 |
83dbd54cde86be0be8742b8fbaf8997c602e9d265e8c18d50056500cb6acf84b
|