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.
Currently it allows you to use the following classes of model:
- AnthropicModel (used with Anthropic's set of models such as
claude-3-haiku
,claude-3-sonnet
,claude-3-opus
andclaude-3_5-sonnet
) - OpenAIModel (used with OpenAI's set of models such as
gpt-3.5-turbo
,gpt-4
andgpt-4o
) - VertexAIChatModel (used with Google Vertex AI's chat models such as
chat-bison
) - VertexAITextGenerationModel (used with Google Vertex AI's text generation models such as
text-bison
) - VertexAIGenerativeModel (used with Google Vertex AI's generative models such as
gemini-pro
)
Modelsmith provides a unified interface over all of these. It has been designed to be extensible and can adapt to other models in the future.
- 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 prompt template is provided but you can also specify your own.
- 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.
Install Modelsmith using pip or your favourite python package manager.
pip
example:
pip install modelsmith
For detailed documentation please have a look at https://christo-olivier.github.io/modelsmith
If you have any questions or suggestions, feel free to open an issue or start a discussion.
This project is licensed under the terms of the MIT License.