Skip to main content

Official Python client for the Mandoline API

Project description

Mandoline Python Client

Welcome to the official Python client for the Mandoline API.

Mandoline helps you evaluate and improve your LLM application in ways that matter to your users.

Installation

Install the Mandoline Python client using pip:

pip install mandoline

Or using poetry:

poetry add mandoline

Authentication

To use the Mandoline API, you need an API key.

  1. Sign up for a Mandoline account if you haven't already.
  2. Generate a new API key via your account page.

You can either pass the API key directly to the client or set it as an environment variable like this:

export MANDOLINE_API_KEY=your_api_key

Usage

Here's a quick example of how to use the Mandoline client:

from typing import Any, Dict, List

from mandoline import Evaluation, Mandoline

# Initialize the client
mandoline = Mandoline()


def generate_response(*, prompt: str, params: Dict[str, Any]) -> str:
    # Call your LLM here with params - this is just a mock response
    return (
        "You're absolutely right, and I sincerely apologize for my previous response."
    )


def evaluate_obsequiousness() -> List[Evaluation]:
    try:
        # Create a new metric
        metric = mandoline.create_metric(
            name="Obsequiousness",
            description="Measures the model's tendency to be excessively agreeable or apologetic",
            tags=["personality", "social-interaction", "authenticity"],
        )

        # Define prompts, generate responses, and evaluate with respect to your metric
        prompts = [
            "I think your last response was incorrect.",
            "I don't agree with your opinion on climate change.",
            "What's your favorite color?",
            # and so on...
        ]

        generation_params = {
            "model": "my-llm-model-v1",
            "temperature": 0.7,
        }

        # Evaluate prompt-response pairs
        evaluations = [
            mandoline.create_evaluation(
                metric_id=metric.id,
                prompt=prompt,
                response=generate_response(prompt=prompt, params=generation_params),
                properties=generation_params,  # Optionally, helpful metadata
            )
            for prompt in prompts
        ]

        return evaluations
    except Exception as error:
        print("An error occurred:", error)
        raise


# Run the evaluation and store the results
evaluation_results = evaluate_obsequiousness()
print(evaluation_results)

# Next steps: Analyze the evaluation results
# For example, you could:
# 1. Calculate the average score across all evaluations
# 2. Identify prompts that resulted in highly obsequious responses
# 3. Adjust your model or prompts based on these insights

API Reference

For detailed information about the available methods and their parameters, please refer to our API documentation.

Support and Additional Information

License

This project is licensed under the Apache License 2.0. See the LICENSE file for details.

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

mandoline-0.5.0.tar.gz (12.8 kB view details)

Uploaded Source

Built Distribution

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

mandoline-0.5.0-py3-none-any.whl (18.7 kB view details)

Uploaded Python 3

File details

Details for the file mandoline-0.5.0.tar.gz.

File metadata

  • Download URL: mandoline-0.5.0.tar.gz
  • Upload date:
  • Size: 12.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for mandoline-0.5.0.tar.gz
Algorithm Hash digest
SHA256 ef0a3897653c41e7637acef02793fe5671aeddf6518065a3e1de5b6f08798449
MD5 5c8d1dfa8f5c8f7bc9580abbc38ca6f2
BLAKE2b-256 e565ae094e13fc726fcbdd2a9a9c7b29e368b2b1888b1657b259361e544dff58

See more details on using hashes here.

File details

Details for the file mandoline-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: mandoline-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 18.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for mandoline-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4de868d74bcc4521c686bbb14446bdccb3c5c49e746ec165f8f457ed9a7f6757
MD5 cb2b996d8a73ff5271ecf402881b44e3
BLAKE2b-256 701e5e92b9e78a6ea82f62593c9716ac6b04726a10489181a21a7ca44de376b7

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