Skip to main content

DataRobot Monitoring and Moderation framework

Project description

DataRobot Moderations library

This library enforces the intervention in the prompt and response texts as per the guard configuration set by the user.

The library accepts the guard configuration in the yaml format and the input prompts and outputs the dataframe with the details like:

  • should the prompt be blocked
  • should the completion be blocked
  • metric values obtained from the model guards
  • is the prompt or response modifed as per the modifier guard configuration

Architecture

The library is architected in a way that it wraps around the typical LLM prediction method. The library will first run the pre-score guards - the guards that will evaluate prompts and enforce moderation if necessary. All the prompts that were not moderated by the library are forwarded to the actual LLM to get their respective completions. The library then evaluates these completions using post-score guards and enforces intervention on them.

How to build it?

The repository uses poetry to manage the build process and a wheel can be built using:

make clean
make

How to use it?

A wheel file generated or downloaded can be installed with pip and will pull its dependencies as well.

pip3 install datarobot-moderations

With DRUM

As described above the library nicely wraps DRUM's score method for pre and post score guards. Hence, in case of DRUM, the user simply runs her custom model using drum score and can avail the moderation library features.

pip3 install datarobot-drum
drum score --verbose --logging-level info --code-dir ./ --input ./input.csv --target-type textgeneration --runtime-params-file values.yaml

Please refer to the DRUM documentation on how to define custom inference model which will walk you through how to assemble custom inference model to how to test it locally using drum score method

Standalone use

However, moderation library is not tightly coupled with DRUM and we are actively working towards using this library in non-DRUM use case. run.py is an example on how to use this library in a stand alone way. This example uses Azure OpenAI service to get LLM completions.

export AZURE_OPENAI_API_KEY=<your-azure-openai-api-key>
python run.py --config ./moderation_config.yaml --input ./input.csv --azure-openai-api-base <azure-openai-base-url> --score

This will output the response dataframe with bunch of information indicating which prompts and responses were blocked / reported, why they are blocked / reported etc

run.py also has an example on how to use this library to moderate the chat interface. It also uses Azure OpenAI service to get chat completions:

export AZURE_OPENAI_API_KEY=<your-azure-openai-api-key>
python run.py --config ./moderation_config.yaml --input ./input_chat.csv --azure-openai-api-base <azure-openai-base-url> --chat

It will output the conversation with LLM line by line.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

datarobot_moderations-11.2.11-py3-none-any.whl (75.4 kB view details)

Uploaded Python 3

File details

Details for the file datarobot_moderations-11.2.11-py3-none-any.whl.

File metadata

  • Download URL: datarobot_moderations-11.2.11-py3-none-any.whl
  • Upload date:
  • Size: 75.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.1 CPython/3.11.13 Linux/5.10.245-245.983.amzn2.x86_64

File hashes

Hashes for datarobot_moderations-11.2.11-py3-none-any.whl
Algorithm Hash digest
SHA256 eb6db70874d8fe2042269d869e5bbb50fff343b330689087cf082e7001aca577
MD5 3f4d9344a0f2092c8dec160a2417b8e0
BLAKE2b-256 b7e90442b78a90859ce8f4e9dc5faf28966ce324f42421f87c9b4393bd6c8f40

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