Skip to main content

AI pipeline framework for Python.

Project description

LLMonPy

LLMonPy is a python library that aims to make it easy to build AI systems that generate "good enough" responses 99.9% of the time. LLMonPy makes it easy to use multiple language models (LLMs) to generate responses to prompts, to rank the responses, and to use the best responses as examples to improve the quality of future responses. It also generates question/best answer/worse answer (QBaWa) data that can be used for training models.

Getting Started

Setup Virtual Environment

I recommend setting up a virtual environment to isolate Python dependencies.

python3 -m venv .venv
source .venv/bin/activate

Install Package

Install the package from PyPi - this takes awhile because it also installs the python clients of multiple LLMs:

pip install llmonpy

Environment Variables

LLMonPy uses a lot of models, so you will probably need several API keys to use it. On startup, it looks for these keys and initializes the clients for associated models for the keys it finds. The following environment variables are used:

First Choice Second Choice
LLMONPY_OPENAI_API_KEY OPENAI_API_KEY
LLMONPY_ANTHROPIC_API_KEY ANTHROPIC_API_KEY
LLMONPY_MISTRAL_API_KEY MISTRAL_API_KEY
LLMONPY_GEMINI_API_KEY GEMINI_API_KEY

Testing Setup

To determine what models are available, this command will list the models that are available:

llmonpy models

To test basic prompting, you can use the following command:

llmonpy prompt

To test the tourneys, you can use the following command (it will cost about $0.03 or less):

llmonpy tourney

To test the AdaptiveICLCycle, you can use the following command (it will cost about $0.12 or less):

llmonpy cycle

Creating Prompts

Prompts are classes that inherit from the LLMonPyPrompt class. The class defines the prompt_text and the data that is used to render the prompt (the prompt_text is used in a Jinja2 template). The class must also define a LLMonPyOutput nested class that defines the output of the prompt. If the prompt is used in a tourney, the class must also define a JudgePrompt nested class that inherits from the TournamentJudgePrompt class.

  • prompt_text: Class field that is the text used for a Jinja2 template
  • constructor: The constructor defines the data that is used to render the prompt
  • to_dict: Method that returns a dictionary of the data that is used to render the prompt and to store the input data in the trace
  • LLMonPyOutput: Nested class that defines the output of the prompt
  • JudgePrompt: Inherits from TournamentJudgePrompt and is used to rank 2 outputs from the prompt. The output of a JudgePrompt is always TournamentJudgePrompt.LLMonPyOutput

You can see an example of a prompt in the steps_prompt.py file. If a prompt is used in an AdaptiveICLCycle, the prompt will probably include {% if example_list %}. Example_list is a list of examples of good responses. The data are instances of the LLMonPyOutput class.

Tourneys

Tourneys are LLMonPySteps that use the LLMonPyTournament class to have multiple LLMs generate responses to a prompt. It then ranks the responses by using LLM judges to compare each output against every other output. The winner of the tourney is the response with the most victories. There is an example of a tourney in steps_prompt.py file.

AdaptiveICLCycle

The AdaptiveICLCycle use a tourney to generate a list of examples of good responses. It then re-runs the tourney with the good responses used as examples to improve the quality of the responses. The cycle continues until it reaches a limit you set or the responses have stopped improving. There is an example of a cycle in steps_prompt.py file.

Trace Viewer

LLMonPy has a trace viewer that can help you understand how your pipeline is working. To start it use this command:

llmonpy_viewer

The UI is at http://localhost:2304 and looks like this:



The trace viewer lets you see the "Victory Report" of tourneys and cycles. It also lets you see the input data, output data, the logs for each step and the sub-steps of each step. The Victory Report divides the total cost of each model's responses by the number of victories the model had in one on one battles. The trace data is stored in the "data" directory in your project directory. It is stored in a SQLite database.

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

llmonpy-0.1.6.tar.gz (2.3 MB view details)

Uploaded Source

Built Distribution

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

llmonpy-0.1.6-py3-none-any.whl (2.3 MB view details)

Uploaded Python 3

File details

Details for the file llmonpy-0.1.6.tar.gz.

File metadata

  • Download URL: llmonpy-0.1.6.tar.gz
  • Upload date:
  • Size: 2.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.0

File hashes

Hashes for llmonpy-0.1.6.tar.gz
Algorithm Hash digest
SHA256 0e6bde32169ccca693f98c0b99a8944d9266362fa7f38057cf79116a97e01e54
MD5 59ab7156b0cc478cd6baa589495bea18
BLAKE2b-256 3ab27254596fab9f10ef5cc2f7579b844197cb81055a4b829dc7d76727a4fe69

See more details on using hashes here.

File details

Details for the file llmonpy-0.1.6-py3-none-any.whl.

File metadata

  • Download URL: llmonpy-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 2.3 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.0

File hashes

Hashes for llmonpy-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 c7d09b4da4e2626a40146c436a64987ae007a21a0686c21304865f32c0f90017
MD5 b09ca671418b33372c9186d3c556394e
BLAKE2b-256 39f7b5ba5f569e7eabb3757763df553b81d88d68116dde43e47c98f3ca8c8fb8

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