Skip to main content

Helper functions for Melodi

Project description

Melodi

Melodi is a platform for feedback, QA, and online evaluations of LLM applications. The python SDK is a set of helper functions built on our public APIs including:

  • Production: Logging and end user feedback
  • Pre-production: Programmatically create experiments for Expert Review in the Melodi UI for rating LLM outputs, editing LLM calls for ideal/golden datasets, and AB/preference testing.

For a working example, please review the quickstart notebook

Installation

To install melodi, use pip:

pip install melodi

Setup

from melodi.api import MelodiClient
from melodi.data_models import (
    BinarySample,
    BakeoffSample,
    FeedbackSample,
    Feedback,
    User,
    Item
)

os.environ["MELODI_API_KEY"] = "<YOUR_KEY>"

client = MelodiClient(verbose=True)

Production functions

We provide two main APIs to collect information from your production environment: Log and Feedback

Create log

Logs are used to track production LLM responses after the response has been generated. Online auto-evaluators can be configured in Melodi to monitor your logs and send alerts via slack.

item = Item(projectName="My First Project", versionName="1.0", data={"key": "value"})
client.create_log(item)

Create user feedback

This API is intended to collect in app, end-user feedback via your production UI. This is distinct from Expert Reviews, which use the Melodi app to collect direct evaluations from your team.

For convenience, we also provide a react component, which is built on this API:

sample = FeedbackSample(
    project="My First Project",
    projectVersion="1.0",
    input="Some input data",
    output="Some output data",
    metadata={"key": "value"}
)

feedback = Feedback(
    feedbackType="POSITIVE",
    feedbackText="This is some positive feedback"
)

user = User(
    id="userid123",
    email="user@example.com"
)

client.create_feedback(sample, feedback, user)

Pre-production functions

These functions are designed to be incorporated into your experimentation and pre-production process. Typically, these functions are used in a notebook setting, where you're experimenting and developing a model (or pipeline) before deploying that model into a user facing app. These functions create experiments for manual review in the Melodi Expert Review UI, which can be used by you, your team, or shared externally with customers or labelers to evaluate LLM responses.

  • Binary: A simple pass/fail assessment. Best for initial model validation and for creating ideal/golden datasets by editing model responses in Melodi.
  • Bake-off (aka AB Test): Preference testing between different versions of a model.

Binary Experiment

Batch

binary_samples = client.load_samples(
    file_path="./examples/binary_sample_data.jsonl", experiment_type="binary"
)

client.create_binary_evaluation_experiment(
    name="My Binary Experiment",
    instructions="Here are some instructions",
    samples=binary_samples,
)

One-by-one

Issue a new experiment ID

client.create_experiment(
    name="My First Experiment", instructions="Here are some sample instructions.", project="My First Project"
)

Add an individual sample to experiment

EXP_ID = <YOUR_EXPERIMENT_ID>

sample_A = BinarySample(response="This is a response", title="This is a title")
client.log_binary_sample(experiment_id=EXP_ID, sample=sample_A)

Bake-off Experiment

Batch

bakeoff_samples = client.load_samples(
    file_path="./examples/bakeoff_sample_data.jsonl", experiment_type="bake_off"
)

client.create_bake_off_evaluation_experiment(
    name="My Bake-off Experiment",
    instructions="Here are some instructions",
    comparisons=bakeoff_samples,
    project="Test Project",
)

One-by-one

Issue a new experiment ID

client.create_experiment(
    name="My First Experiment", instructions="Here are some sample instructions.", project="My First Project"
)

Add an individual sample to experiment

EXP_ID = <YOUR_EXPERIMENT_ID>

sample_A = BakeoffSample(version="version A", response="response A")
sample_B = BakeoffSample(version="version B", response="response B")

client.log_bake_off_comparison(
    experiment_id=EXP_ID, sample_1=sample_A, sample_2=sample_B
)

Get a shareable link for Expert Review

This returns a no-auth link so that you can collect Expert Reviews without having to create logins for your reviewers.

client.make_shareable(EXP_ID)

Contact

If you have any questions or feedback, please contact info@melodi.fyi

License

This project is licensed under the MIT License.

Copyright 2024, Melodi Ltd.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

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

melodi-0.0.33.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

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

melodi-0.0.33-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

Details for the file melodi-0.0.33.tar.gz.

File metadata

  • Download URL: melodi-0.0.33.tar.gz
  • Upload date:
  • Size: 9.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.1

File hashes

Hashes for melodi-0.0.33.tar.gz
Algorithm Hash digest
SHA256 a74cc96bcc9c93f674e5f0ac8a7c3d280015cf987d7ae1b4cd1da77fba867482
MD5 a738171f5dc9ef5488f9d351170308b4
BLAKE2b-256 6d360c8299bd794b51b8ad6ea6d3cf6b0708db4e672b91f1f394c71e176c8e78

See more details on using hashes here.

File details

Details for the file melodi-0.0.33-py3-none-any.whl.

File metadata

  • Download URL: melodi-0.0.33-py3-none-any.whl
  • Upload date:
  • Size: 7.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.1

File hashes

Hashes for melodi-0.0.33-py3-none-any.whl
Algorithm Hash digest
SHA256 17b88da59b6f31f5be16752d797f6730963ec389aac7f9bd0934ddf50053173b
MD5 2645d5d30d3f2d7ab746a3b958871815
BLAKE2b-256 2b51ca64e3875283e5656f5ab1890f946fc15843eff0df9297b3e10d440ee28e

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