LLMX: A library for LLM Text Generation
pip install llmxLLMX - An API for Chat Fine-Tuned Language Models
A simple python package that provides a unified interface to several LLM providers of chat fine-tuned models [OpenAI, AzureOpenAI, PaLM, Cohere and local HuggingFace Models].
Note llmx wraps multiple api providers and its interface may change as the providers as well as the general field of LLMs evolve.
There is nothing particularly special about this library, but some of the requirements I needed when I started building this (that other libraries did not have):
- Unified Model Interface: Single interface to create LLM text generators with support for multiple LLM providers.
from llmx import llm
gen = llm(provider="openai") # support azureopenai models too.
gen = llm(provider="palm") # or google
gen = llm(provider="cohere") # or palm
gen = llm(provider="hf", model="HuggingFaceH4/zephyr-7b-beta", device_map="auto") # run huggingface model locally
- Unified Messaging Interface. Standardizes on the OpenAI ChatML message format and is designed for chat finetuned models. For example, the standard prompt sent a model is formatted as an array of objects, where each object has a role (
system,user, orassistant) and content (see below). A single request is list of only one message (e.g., write code to plot a cosine wave signal). A conversation is a list of messages e.g. write code for x, update the axis to y, etc. Same format for all models.
messages = [
{"role": "user", "content": "You are a helpful assistant that can explain concepts clearly to a 6 year old child."},
{"role": "user", "content": "What is gravity?"}
]
- Good Utils (e.g., Caching etc): E.g. being able to use caching for faster responses. General policy is that cache is used if config (including messages) is the same. If you want to force a new response, set
use_cache=Falsein thegeneratecall.
response = gen.generate(messages=messages, config=TextGeneratorConfig(n=1, use_cache=True))
Output looks like
TextGenerationResponse(
text=[Message(role='assistant', content="Gravity is like a magical force that pulls things towards each other. It's what keeps us on the ground and stops us from floating away into space. ... ")],
config=TextGenerationConfig(n=1, temperature=0.1, max_tokens=8147, top_p=1.0, top_k=50, frequency_penalty=0.0, presence_penalty=0.0, provider='openai', model='gpt-4', stop=None),
logprobs=[], usage={'prompt_tokens': 34, 'completion_tokens': 69, 'total_tokens': 103})