langchain/libs/experimental/langchain_experimental/llms
Noam Gat 14e8c74736
LM Format Enforcer Integration + Sample Notebook (#12625)
## Description

This PR adds support for
[lm-format-enforcer](https://github.com/noamgat/lm-format-enforcer) to
LangChain.

![image](https://raw.githubusercontent.com/noamgat/lm-format-enforcer/main/docs/Intro.webp)

The library is similar to jsonformer / RELLM which are supported in
Langchain, but has several advantages such as
- Batching and Beam search support
- More complete JSON Schema support
- LLM has control over whitespace, improving quality
- Better runtime performance due to only calling the LLM's generate()
function once per generate() call.

The integration is loosely based on the jsonformer integration in terms
of project structure.

## Dependencies

No compile-time dependency was added, but if `lm-format-enforcer` is not
installed, a runtime error will occur if it is trying to be used.

## Tests

Due to the integration modifying the internal parameters of the
underlying huggingface transformer LLM, it is not possible to test
without building a real LM, which requires internet access. So, similar
to the jsonformer and RELLM integrations, the testing is via the
notebook.

## Twitter Handle

[@noamgat](https://twitter.com/noamgat)


Looking forward to hearing feedback!

---------

Co-authored-by: Bagatur <baskaryan@gmail.com>
2023-10-31 09:49:01 -07:00
..
__init__.py LM Format Enforcer Integration + Sample Notebook (#12625) 2023-10-31 09:49:01 -07:00
anthropic_functions.py Fix Anthropic Functions ainvoke (#12215) 2023-10-24 10:07:01 -07:00
jsonformer_decoder.py Upgrade experimental package dependencies and use Poetry 1.6.1. (#11339) 2023-10-16 21:13:31 -04:00
llamaapi.py Runnable single protocol (#7800) 2023-07-26 12:16:46 -07:00
lmformatenforcer_decoder.py LM Format Enforcer Integration + Sample Notebook (#12625) 2023-10-31 09:49:01 -07:00
rellm_decoder.py Upgrade experimental package dependencies and use Poetry 1.6.1. (#11339) 2023-10-16 21:13:31 -04:00