Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

community: Outlines integration #27449

Open
wants to merge 44 commits into
base: master
Choose a base branch
from

Conversation

shroominic
Copy link
Contributor

In collaboration with @rlouf I build an outlines integration for langchain!

I think this is really useful for doing any type of structured output locally.
Dottxt spend alot of work optimising this process at a lower level (outlines-core written in rust) so I think this is a better alternative over all current approaches in langchain to do structured output.
It also implements the .with_structured_output method so it should be a drop in replacement for a lot of applications.

The integration includes:

  • Outlines LLM class
  • ChatOutlines class
  • Tutorial Cookbooks
  • Documentation Page
  • Validation and error messages
  • Exposes Outlines Structured output features
  • Support for multiple backends
  • Integration and Unit Tests

Dependencies: outlines + additional (depending on backend used)

I am not sure if the unit-tests comply with all requirements, if not I suggest to just remove them since I don't see a useful way to do it differently.

Quick overview:

Chat Models:
image

Structured Output:
image

Copy link

vercel bot commented Oct 18, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
langchain ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 20, 2024 9:14am

@dosubot dosubot bot added size:XXL This PR changes 1000+ lines, ignoring generated files. community Related to langchain-community labels Oct 18, 2024
@cpfiffer
Copy link

Either I am stupid or the Integration docs lint / build (pull_request) check is broken... It showes ValueError: Document /home/runner/work/langchain/langchain/docs/docs/integrations/chat/outlines.ipynb is missing headers:

  • Installation

But the header is definitlely there!

I'm surprised by this too -- the header is included for sure.

@cpfiffer
Copy link

Ah, I see. I believe the order of credentials and installation should be switched, as per this doc.

@shroominic
Copy link
Contributor Author

Ah, I see. I believe the order of credentials and installation should be switched, as per this doc.

I tried this and run the script locally but still didn't work ...

@cpfiffer
Copy link

Could y'all wait a bit before merging? I want some Outlines people from @dottxt-ai to take a look at this to see how we feel about the interface.

@rlouf
Copy link

rlouf commented Oct 25, 2024

Looks good to me 🫡

Copy link
Contributor

@vbarda vbarda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution -- looks good overall! Added a few comments

libs/community/langchain_community/chat_models/outlines.py Outdated Show resolved Hide resolved
libs/community/langchain_community/chat_models/outlines.py Outdated Show resolved Hide resolved
libs/community/langchain_community/chat_models/outlines.py Outdated Show resolved Hide resolved
libs/community/langchain_community/chat_models/outlines.py Outdated Show resolved Hide resolved
libs/community/langchain_community/chat_models/outlines.py Outdated Show resolved Hide resolved
libs/community/langchain_community/chat_models/outlines.py Outdated Show resolved Hide resolved
libs/community/langchain_community/chat_models/outlines.py Outdated Show resolved Hide resolved
libs/community/langchain_community/chat_models/outlines.py Outdated Show resolved Hide resolved
@vbarda
Copy link
Contributor

vbarda commented Oct 31, 2024

Could you add some unittests as well?

@shroominic
Copy link
Contributor Author

Could you add some unittests as well?

I added unit-tests before but removed them because I could not find a useful way to do them without requiring network connection since outlines requires local models and you initialize the chat model with a hugging face model id.
https://github.com/langchain-ai/langchain/blob/30071e3182459caa975c16a84b3e22ab7e2a94d3/libs/community/tests/unit_tests/llms/test_outlines.py

@vbarda
Copy link
Contributor

vbarda commented Nov 5, 2024

Could you add some unittests as well?

I added unit-tests before but removed them because I could not find a useful way to do them without requiring network connection since outlines requires local models and you initialize the chat model with a hugging face model id. https://github.com/langchain-ai/langchain/blob/30071e3182459caa975c16a84b3e22ab7e2a94d3/libs/community/tests/unit_tests/llms/test_outlines.py

yea, you would probably need to do some mocking for the model interfaces to avoid network connections or using local models. primarily it would be nice to test different scenarios for constraints validation etc. you could also factor some of those out outside the classes and that would also make it easier to test

@shroominic
Copy link
Contributor Author

Could you add some unittests as well?

I added unit-tests before but removed them because I could not find a useful way to do them without requiring network connection since outlines requires local models and you initialize the chat model with a hugging face model id. https://github.com/langchain-ai/langchain/blob/30071e3182459caa975c16a84b3e22ab7e2a94d3/libs/community/tests/unit_tests/llms/test_outlines.py

yea, you would probably need to do some mocking for the model interfaces to avoid network connections or using local models. primarily it would be nice to test different scenarios for constraints validation etc. you could also factor some of those out outside the classes and that would also make it easier to test

@vbarda
Copy link
Contributor

vbarda commented Nov 15, 2024

@shroominic thanks for adding the tests! i think it's almost ready to merge -- docs page for LLMs is failing (the chat model one is correct)

ValueError: Document /home/runner/work/langchain/langchain/docs/docs/integrations/llms/outlines.ipynb is missing headers

@shroominic
Copy link
Contributor Author

everything passing 🙌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community Related to langchain-community size:XXL This PR changes 1000+ lines, ignoring generated files.
Projects
Status: In review
Development

Successfully merging this pull request may close these issues.

4 participants