LMQL (Language Model Query Language) is a programming language that allows users to express natural language prompts that also contain code, which can be executed on language models like OpenAI’s GPT models. LMQL is an open-source programming language based on a superset of Python that goes beyond traditional templating languages by providing full Python support, yet a lightweight programming interface. LMQL is designed to make working with language models like OpenAI easier and more expressive.
LMQL can capture a wide range of state-of-the-art prompting methods, such as interactive flows, that are difficult to implement with existing APIs. LMQL constraints allow users to guide or steer the text generation process according to their desired specifications, like ensuring that the generated text follows certain grammatical or syntactic rules or that certain words or phrases are being avoided. LMQL is a powerful tool that can improve the accuracy on numerous downstream tasks while significantly reducing computation or cost in pay-to-use APIs, resulting in 13-85% cost savings.
- Scripted Prompts: LMQL generalizes natural language prompting, making it more expressive while remaining accessible. For this, LMQL builds on top of Python, allowing users to express natural language prompts that also contain code
- Fixed Answer Templates and Intermediate Instructions: These allow the user to steer the LLM’s reasoning process
- Multi-Model Support: Seamlessly use LMQL with OpenAI API, Azure OpenAI, and Transformers models
- Extensive Applications: Use LMQL to implement advanced applications like schema-safe JSON decoding, algorithmic prompting, interactive chat interfaces, and inline tool use
Overall, LMQL is a promising development in the field of language model programming, as it allows users to specify constraints on the language model’s output, facilitating effortless adaptation to a multitude of tasks while abstracting the inner workings of the language model and providing high-level.