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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file melodi-0.1.0.tar.gz.
File metadata
- Download URL: melodi-0.1.0.tar.gz
- Upload date:
- Size: 11.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1a469a660c595f2fb887c55e76052ef4ac49604d71634ce4db04594dce1b8fe5
|
|
| MD5 |
920a543bc749d0a029432a3c04ad9417
|
|
| BLAKE2b-256 |
418f866cb5aa1ddde344d99ec956fe43ebd001835e1ac50c09230d37fe06aec8
|
File details
Details for the file melodi-0.1.0-py3-none-any.whl.
File metadata
- Download URL: melodi-0.1.0-py3-none-any.whl
- Upload date:
- Size: 15.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e6d70f039b04bed19ec0a7d5d38a1e9b07c63ffb578f6e18b352dbab624d0724
|
|
| MD5 |
1a6704f34ef8c54ecb4bdc2d02486895
|
|
| BLAKE2b-256 |
727490ea38afff70cfbba412063632e15e044e1fa113be8bf2de58121c9f9d86
|