Skip to content

Work with both Pydantic 1 and 2 #121

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

Merged
merged 2 commits into from
Jul 19, 2023
Merged

Work with both Pydantic 1 and 2 #121

merged 2 commits into from
Jul 19, 2023

Conversation

simonw
Copy link
Contributor

@simonw simonw commented Jul 18, 2023

Refs:

My LLM project uses Pydantic 2 and I want to build a plugin for it (llm-replicate) that adds support for querying Replicate models - but I can't do that easily if Replicate is pinned to Pydantic 1.0.

It looks like it's possible to support both using this idiom:

try:
    from pydantic import v1 as pydantic
except ImportError:
    import pydantic

Since 2.0 introduced a v1 backwards compatibility shim.

Copy link
Contributor

@mattt mattt left a comment

Choose a reason for hiding this comment

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

Thanks so much for your PR, @simonw! And thanks for building a Replicate plugin for llm.

I wasn't aware of the Pydantic 2 having a v1 shim, so that's really helpful. I merged #113 as stopgap measure, but hadn't circled back to implement a proper fix.

A linting error was blocking this from getting merged, so I applied a change to fix that.

@mattt mattt merged commit 31ba3ed into replicate:main Jul 19, 2023
@mattt
Copy link
Contributor

mattt commented Jul 19, 2023

This is now available in version 0.9.0. Thanks again for your help, @simonw!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants