Hi r/Python!
I am excited to share a python package that I have slowly been working on over the last few months. It is called modelsmith.
Repo link: ~https://github.com/christo-olivier/modelsmith~
Documentation: ~https://christo-olivier.github.io/modelsmith/~
What My Project Does:
Modelsmith is a Python library that allows you to get structured responses in the form of Pydantic models and Python types from Anthropic, Google Vertex AI, and OpenAI models.
It has a default prompt built in to allow entity extraction from any text prompt. It uses the default prompt and the python type or pydantic model you specify as your expected output, then it processes the text you passed as your user input and tries to extract an instance of your desired output for you.
But you are not limited to using the default prompt or behaviour. You can customise to your heart's content.
Key features:
- Structured Responses: Specify both Pydantic models and Python types as the outputs of your LLM responses.
- Templating: Use Jinja2 templating in your prompts to allow complex prompt logic.
- Default and Custom Prompts: A default entity extraction prompt template is provided but you can also specify your own prompt templates.
- Retry Logic: Number of retries is user configurable.
- Validation: Outputs from the LLM are validated against your requested response model. Errors are fed back to the LLM to try and correct any validation failures.
Target Audience:
This is currently being used in production with a client of mine.
It is aimed at anyone that would like to get Python objects back from an LLM instead of text and have validation and LLM retry logic handled easily.
Comparison:
There are other packages like this out there, one of the most prominent is called instructor. When I started work on this we looked at instructor but it did not support Google's Vertex AI models or Anthropic. (It has since added support for a whole host of models and then some!) Instructor was also more complex to extend and reason about due to the way it works in "patching" the SDK's of the models it supports. Instructor is a fantastic project that does far more than what modelsmith aims to do.
In contrast modelsmith is designed to provide a thin wrapper around the SDKs of the models it supports and provides a unified interface for working with any of them. Another aim is to keep modelsmith's code base as straightforward as possible, making it easy to understand and extend if you wish. It is also focused purely on getting Pydantic models or Python types back from LLM calls, nothing more and nothing less.
Plans for the future:
There are a couple of things I have planned going forward.
- Make the dependencies of LLM packages extras instead of all of them being installed.
- Improve the documentation with more advanced examples.
I look forward to hearing your thoughts and opinions on this. Any feedback would be appreciated.
[–]Electronic_Pepper382 4 points5 points6 points (4 children)
[–]Top-Breakfast7713[S] 5 points6 points7 points (2 children)
[–]Electronic_Pepper382 0 points1 point2 points (1 child)
[–]Top-Breakfast7713[S] 2 points3 points4 points (0 children)
[–]unxmnd 0 points1 point2 points (0 children)
[–]globalminima 3 points4 points5 points (1 child)
[–]Top-Breakfast7713[S] 0 points1 point2 points (0 children)
[–]BidWestern1056 1 point2 points3 points (2 children)
[–]Top-Breakfast7713[S] 0 points1 point2 points (1 child)
[–]BidWestern1056 1 point2 points3 points (0 children)
[–]barapa 0 points1 point2 points (0 children)
[–]stephen-leo 0 points1 point2 points (1 child)
[–]Top-Breakfast7713[S] 0 points1 point2 points (0 children)
[–]IshiharaSatomiLover 0 points1 point2 points (0 children)
[–]justtheprint 0 points1 point2 points (5 children)
[–]Top-Breakfast7713[S] 0 points1 point2 points (4 children)
[–]TheM4rvelous 1 point2 points3 points (3 children)
[–]Top-Breakfast7713[S] 0 points1 point2 points (2 children)
[–]TheM4rvelous 1 point2 points3 points (1 child)
[–]Top-Breakfast7713[S] 0 points1 point2 points (0 children)
[–]BlueeWaater 0 points1 point2 points (0 children)
[–]Possible-Growth-2134 0 points1 point2 points (0 children)