Skip to main content

bettershot 💡🚀

⚡️ A Python package for adding error monitoring to LLM Apps in a few minutes ⚡

BetterShot by BerriAI let’s you add error (hallucinations/refusal to answer) monitoring to your LLM App in a few minutes. Like Bugsnag/Sentry for LLM apps!

Getting Started

Install bettershot by running this command.:

pip install bettershot

Using bettershot

It's just 1 line of code:

log(messages=messages, completion=result, user_email="YOUR_EMAIL", query=query)

7f11c616-853a-4016-802c-ef705dea51c7

Dashboard

All your logs are available @ 'https://better-test.vercel.app/' + YOUR_EMAIL

e.g. log(messages=messages, completion=result, user_email="krrish@berri.ai", query=query)

will have it's results logged @

https://better-test.vercel.app/krrish@berri.ai

Implementation

Here are all the items you can log:

Parameter Type Required/Optional Description
messages List Required The list of messages sent to the OpenAI chat completions endpoint
completion Dictionary Required The response received from the OpenAI chat completions endpoint
user_email String Required Your user email
query String Required The query being asked by your user
customer_id String Optional A way to identify your customer

Here's 2 examples of using it:

Calling the 'raw' OpenAI API

from bettershot import log
import openai 

def simple_openai_call(query):
    messages = [{'role': 'user', 'content': query}]
    completion = openai.ChatCompletion.create(
                model="gpt-3.5-turbo",
                messages=messages
    
            )
    log(messages=messages, completion=completion, user_email="YOUR_EMAIL", query=query, customer_id="fake_user@fake_accounts.xyz") #JUST 1 LINE OF CODE 🤯

simple_openai_call("hey! how's it going?")

Calling the Langchain OpenAI API

import openai
import langchain 
from bettershot import log

def simple_langchain_call(query):
    chat = ChatOpenAI(model="gpt-3.5-turbo", temperature=0.7)
    prompt = "You are an extremely intelligent AI assistant for BerriAI, answer all questions resepectfully and in a warm tone"
    messages = [
      SystemMessage(content=prompt),
      HumanMessage(content=query)
    ]
    result = chat(messages)
    log(messages=messages, completion=completion, user_email="YOUR_EMAIL", query=query, customer_id="fake_user@fake_accounts.xyz") #JUST 1 LINE OF CODE 🎉 

simple_langchain_call("hey! how's it going?")

bettershot automatically evaluates your OpenAI responses to determine if the model either invented new information (hallucination) or refused to answer ("Sorry, as an AI language model...") a user's question.

How does eval work?

Reliable + Fast testing is hard, and that's what we want to tackle.

Each question is evaluated 3 times.

Each evaluation returns either True or False, along with the model's rationale for why it chose what it did.

We pick the evaluation (True/False) that occurs most, along with the model rationale to explain reasoning.

Each question is run in parallel and results are added to your dashboard in real-time.

We will be sharing the prompts soon!

Contributing

We welcome contributions to bettershot! Feel free to create issues/PR's/or DM us (👋 Hi I'm Krrish - +17708783106)

License

bettershot is released under the MIT License.

Release files for bettershot 0.1.92

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bettershot 0.1.92
File Size Uploaded
bettershot-0.1.92.tar.gz 2.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for bettershot 0.1.92
File Interpreter ABI Platform
bettershot-0.1.92-py3-none-any.whl Python 3 none any Details

Total release size: 6.1 kB

Release files / bettershot-0.1.92.tar.gz

Download URL bettershot-0.1.92.tar.gz
Size 2.8 kB
Tags Source
SHA-256 checksum
How to use checksums
8333bf9aedf223aa356a5cebd51f5cdfac3f8109165468c96109f4f7c95cc27a
BLAKE2b-256 checksum
How to use checksums
e64d0483fd495b6cb5facf1f73964d4b9e13acfdd8b78012c31600cca98bf8f4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.5.1 CPython/3.11.3 Darwin/19.6.0

Release files / bettershot-0.1.92-py3-none-any.whl

Download URL bettershot-0.1.92-py3-none-any.whl
Size 3.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
89db56a5c06d7f0632a5180ef321b75042dc2e6177a2c9f27ae482611ecd7f5e
BLAKE2b-256 checksum
How to use checksums
f014fdd4d73a71c1ba403ed17169e74a9a74f712eba09b3b5d0f9321a991208a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.5.1 CPython/3.11.3 Darwin/19.6.0

Release history Release notifications | RSS feed

This release

0.1.92 This release

2 release files

0.1.91

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page