Skip to main content

Patronus Python SDK

Project description

Patronus Python SDK

The Patronus Python SDK is a Python library for systematic evaluation of Large Language Models (LLMs). Build, test, and improve your LLM applications with customizable tasks, evaluators, and comprehensive experiment tracking.

Note: This library is currently in beta and is not stable. The APIs may change in future releases.

Documentation

For detailed documentation, including API references and advanced usage, please visit our documentation.

Installation

pip install patronus

Quickstart

Evaluation

For quick testing and exploration, you can use the synchronous evaluate() method:

import os
from patronus import Client

client = Client(
    # This is the default and can be omitted
    api_key=os.environ.get("PATRONUS_API_KEY"),
)
result = client.evaluate(
    evaluator="lynx",
    criteria="patronus:hallucination",
    evaluated_model_input="Who are you?",
    evaluated_model_output="My name is Barry.",
    evaluated_model_retrieved_context="My name is John.",
)
print(f"Pass: {result.pass_}")
print(f"Explanation: {result.explanation}")

The Patronus Python SDK is designed to work primarily with async/await patterns, which is the recommended way to use the library. Here's a feature-rich example using async evaluation:

import asyncio
from patronus import Client

client = Client()

no_apologies = client.remote_evaluator(
    "judge",
    "patronus:no-apologies",
    explain_strategy="always",
    max_attempts=3,
)


async def evaluate():
    result = await no_apologies.evaluate(
        evaluated_model_input="How to kill a docker container?",
        evaluated_model_output="""
        I cannot assist with that question as it has been marked as inappropriate.
        I must respectfully decline to provide an answer."
        """,
    )
    print(f"Pass: {result.pass_}")
    print(f"Explanation: {result.explanation}")


asyncio.run(evaluate())

Experiment

The Patronus Python SDK includes a powerful experimentation framework designed to help you evaluate, compare, and improve your AI models. Whether you're working with pre-trained models, fine-tuning your own, or experimenting with new architectures, this framework provides the tools you need to set up, execute, and analyze experiments efficiently.

import os
from patronus import Client, Row, TaskResult, evaluator, task

client = Client(
    # This is the default and can be omitted
    api_key=os.environ.get("PATRONUS_API_KEY"),
)


@task
def my_task(row: Row):
    return f"{row.evaluated_model_input} World"


@evaluator
def exact_match(row: Row, task_result: TaskResult):
    # exact_match is locally defined and run evaluator
    return task_result.evaluated_model_output == row.evaluated_model_gold_answer


# Reference remote Judge Patronus Evaluator with is-concise criteria.
# This evaluator runs remotely on Patronus infrastructure.
is_concise = client.remote_evaluator("judge", "patronus:is-concise")

client.experiment(
    "Tutorial Project",
    dataset=[
        {
            "evaluated_model_input": "Hello",
            "evaluated_model_gold_answer": "Hello World",
        },
    ],
    task=my_task,
    evaluators=[exact_match, is_concise],
)

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

patronus-0.0.15.tar.gz (27.2 kB view details)

Uploaded Source

Built Distribution

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

patronus-0.0.15-py3-none-any.whl (31.6 kB view details)

Uploaded Python 3

File details

Details for the file patronus-0.0.15.tar.gz.

File metadata

  • Download URL: patronus-0.0.15.tar.gz
  • Upload date:
  • Size: 27.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.8 Darwin/23.4.0

File hashes

Hashes for patronus-0.0.15.tar.gz
Algorithm Hash digest
SHA256 91abcb30bd67d3963f7b25b837389d0739f7cac45da63bb90c71ac7477db43ad
MD5 95b57e5267f44fc52728288057b00b6d
BLAKE2b-256 a4b2f6c024cdd0ec25126fb7ec57487231c9f7034861c6732bfb52a26fddd4f3

See more details on using hashes here.

File details

Details for the file patronus-0.0.15-py3-none-any.whl.

File metadata

  • Download URL: patronus-0.0.15-py3-none-any.whl
  • Upload date:
  • Size: 31.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.8 Darwin/23.4.0

File hashes

Hashes for patronus-0.0.15-py3-none-any.whl
Algorithm Hash digest
SHA256 ab1d04c445a686783fd9cfa943eeb110d994aadc9686c2ce8c8afb5f63fac852
MD5 37def38b0a3526c0815977ab9db2a7fd
BLAKE2b-256 3c576cd4b2e52f68af7129b3d9b80e1ea8335640de978ae9d0f09878f1d36057

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