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

Pydantic v1 and v2 compatibility #466

Merged
merged 7 commits into from
Nov 15, 2023
Merged

Conversation

JasonWeill
Copy link
Collaborator

Fixes #390. Allows Pydantic v1 or v2 to be used with Jupyter AI. Internally, Jupyter AI continues to use Pydantic v1, but using the langchain.pydantic_v1 package, we can import the pydantic.v1 package if the user has Pydantic v2 installed.

Updates the user docs to refer to the Pydantic compatibility guide in LangChain.

@JasonWeill JasonWeill added enhancement New feature or request @jupyter-ai/core labels Nov 13, 2023
@3coins
Copy link
Collaborator

3coins commented Nov 13, 2023

@JasonWeill
This was rejected in #375. What version of pydantic would work for example, if a user has a package that creates a new provider for Jupyter AI?

@JasonWeill
Copy link
Collaborator Author

@JasonWeill This was rejected in #375. What version of pydantic would work for example, if a user has a package that creates a new provider for Jupyter AI?

We talked about this earlier today: depending on LangChain's pydantic_v1 class will make us rely on LangChain's pass-through implementation of either pydantic (if the user has Pydantic v. 1.x) or pydantic.v1 (if v. 2.x). That concern about LangChain blocked #375 in late August, but at this point, I think that (a) we are wedded to LangChain until we do our next major version bump, at least; and (b) LangChain's Pydantic implementation does not appear likely to change anytime soon.

Following the guidance from LangChain, users who are building on top of Jupyter AI will be expected to use Pydantic v1 classes, to prevent conflicts. This is in LangChain's docs about Pydantic v1, which I link to from our docs as revised in this PR.

packages/jupyter-ai-magics/pyproject.toml Outdated Show resolved Hide resolved
docs/source/users/index.md Show resolved Hide resolved
@dlqqq dlqqq changed the title Pydantic v1 and v2 support Pydantic v1 and v2 compatibility Nov 15, 2023
docs/source/developers/index.md Outdated Show resolved Hide resolved
@JasonWeill JasonWeill merged commit 2c89d13 into jupyterlab:main Nov 15, 2023
6 checks passed
@JasonWeill
Copy link
Collaborator Author

@meeseeksdev please backport to 1.x

Copy link

lumberbot-app bot commented Nov 15, 2023

Owee, I'm MrMeeseeks, Look at me.

There seem to be a conflict, please backport manually. Here are approximate instructions:

  1. Checkout backport branch and update it.
git checkout 1.x
git pull
  1. Cherry pick the first parent branch of the this PR on top of the older branch:
git cherry-pick -x -m1 2c89d139a8205f1fcd318cfd922e1771df7564ef
  1. You will likely have some merge/cherry-pick conflict here, fix them and commit:
git commit -am 'Backport PR #466: Pydantic v1 and v2 compatibility'
  1. Push to a named branch:
git push YOURFORK 1.x:auto-backport-of-pr-466-on-1.x
  1. Create a PR against branch 1.x, I would have named this PR:

"Backport PR #466 on branch 1.x (Pydantic v1 and v2 compatibility)"

And apply the correct labels and milestones.

Congratulations — you did some good work! Hopefully your backport PR will be tested by the continuous integration and merged soon!

Remember to remove the Still Needs Manual Backport label once the PR gets merged.

If these instructions are inaccurate, feel free to suggest an improvement.

JasonWeill added a commit to JasonWeill/jupyter-ai that referenced this pull request Nov 15, 2023
* Revert "Copy edits for Jupyternaut messages"

This reverts commit f24bb76.

* Uses langchain.pydantic_v1 for compatibility

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Removes pydantic as a dependency, now that we use it via langchain

* Adds developer docs, removes remaining dependency

* Doc edits per @dlqqq

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
(cherry picked from commit 2c89d13)
JasonWeill added a commit that referenced this pull request Nov 15, 2023
* Revert "Copy edits for Jupyternaut messages"

This reverts commit f24bb76.

* Uses langchain.pydantic_v1 for compatibility

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Removes pydantic as a dependency, now that we use it via langchain

* Adds developer docs, removes remaining dependency

* Doc edits per @dlqqq

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
(cherry picked from commit 2c89d13)
dbelgrod pushed a commit to dbelgrod/jupyter-ai that referenced this pull request Jun 10, 2024
* Revert "Copy edits for Jupyternaut messages"

This reverts commit f24bb76.

* Uses langchain.pydantic_v1 for compatibility

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Removes pydantic as a dependency, now that we use it via langchain

* Adds developer docs, removes remaining dependency

* Doc edits per @dlqqq

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Marchlak pushed a commit to Marchlak/jupyter-ai that referenced this pull request Oct 28, 2024
* Revert "Copy edits for Jupyternaut messages"

This reverts commit f24bb76.

* Uses langchain.pydantic_v1 for compatibility

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Removes pydantic as a dependency, now that we use it via langchain

* Adds developer docs, removes remaining dependency

* Doc edits per @dlqqq

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request @jupyter-ai/core
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Jupyter-ai with Pydantic v2 not work?
4 participants