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.56.tar.gz (10.8 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.56-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: melodi-0.0.56.tar.gz
  • Upload date:
  • Size: 10.8 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.56.tar.gz
Algorithm Hash digest
SHA256 70fb664f1d4aa54e021a61e6653dd91f89ad56c4b373c509edeb4fafd84e7554
MD5 47d0a0e921c2c3b8d8c8c5f1b1c15cf5
BLAKE2b-256 533089dde6bdad54bbe429a16ccca03b03aa313b35bca33e3d6b3f7f289d94e1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: melodi-0.0.56-py3-none-any.whl
  • Upload date:
  • Size: 9.2 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.56-py3-none-any.whl
Algorithm Hash digest
SHA256 1916b4ed2f1d7228143c52f8c533d9ec48c73cde6fd7b2113e5ed40fb8b6a5a3
MD5 accf45d645187a7694f4a7d429b9c643
BLAKE2b-256 726a8b9bd6785858afda3b54fce0b165c5ad735a47c9243bd5dd7969e7dbf9b7

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