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

Fix warnings from pydantic #3670

Merged
merged 11 commits into from
May 31, 2024

Conversation

lj-wego
Copy link
Contributor

@lj-wego lj-wego commented May 16, 2024

Attempt to fix pydantic warnings.

before:

poetry run pytest . | grep warning
Configuration file exists at /Users/lj/Library/Preferences/pypoetry, reusing this directory.

Consider moving TOML configuration files to /Users/lj/Library/Application Support/pypoetry, as support for the legacy directory will be removed in an upcoming release.
=============================== warnings summary ===============================
../../../../Library/Caches/pypoetry/virtualenvs/litellm-vO9t8ogX-py3.11/lib/python3.11/site-packages/pydantic/_internal/_config.py:284: 25 warnings
    warnings.warn(DEPRECATION_MESSAGE, DeprecationWarning)
-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
======================== 39 warnings, 4 errors in 2.37s ========================

after:

poetry run pytest . | grep warning
Configuration file exists at /Users/lj/Library/Preferences/pypoetry, reusing this directory.

Consider moving TOML configuration files to /Users/lj/Library/Application Support/pypoetry, as support for the legacy directory will be removed in an upcoming release.
=============================== warnings summary ===============================
-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
========================= 1 warning, 4 errors in 2.04s =========================

running same test as #3600:

poetry run pytest litellm/tests/test_proxy_server.py
Configuration file exists at /Users/lj/Library/Preferences/pypoetry, reusing this directory.

Consider moving TOML configuration files to /Users/lj/Library/Application Support/pypoetry, as support for the legacy directory will be removed in an upcoming release.
================================================================== test session starts ==================================================================
platform darwin -- Python 3.11.3, pytest-7.4.4, pluggy-1.5.0
rootdir: /Users/lj/Documents/litellm
plugins: anyio-4.3.0, asyncio-0.23.6, mock-3.14.0
asyncio: mode=Mode.STRICT
collected 12 items                                                                                                                                      

litellm/tests/test_proxy_server.py s..........s                                                                                                   [100%]

=================================================================== warnings summary ====================================================================
litellm/utils.py:59
  /Users/lj/Documents/litellm/litellm/utils.py:59: DeprecationWarning: open_text is deprecated. Use files() instead. Refer to https://importlib-resources.readthedocs.io/en/latest/using.html#migrating-from-legacy for migration advice.
    with resources.open_text("litellm.llms.tokenizers", "anthropic_tokenizer.json") as f:

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
======================================================= 10 passed, 2 skipped, 1 warning in 7.84s ========================================================

Not fixing the import lib warning as it is not explicitly related to pydantic.

Regarding pydantic v1 compatibility
#3600 (comment)

Openai (1.25.1) is using pydantic v2
https://github.com/openai/openai-python/blob/aed1e43745cd6358b4bafd3a39b3dfeee5e31a03/requirements.lock#L40

Relevant issues

Fixes #3417
#3600
#3664

Type

🐛 Bug Fix
🧹 Refactoring

Copy link

vercel bot commented May 16, 2024

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

Name Status Preview Comments Updated (UTC)
litellm ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 31, 2024 3:39am

@lj-wego lj-wego changed the title Fix warnings from pydanticx Fix warnings from pydantic May 16, 2024
@lj-wego lj-wego marked this pull request as ready for review May 16, 2024 09:30
@lj-wego lj-wego mentioned this pull request May 16, 2024
@@ -84,3 +84,5 @@ version_files = [
"pyproject.toml:^version"
]

[tool.mypy]
plugins = "pydantic.mypy"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This "fixes" this error:
image

mypy treats model_config assignment as an unintended override -- when it is.
Adding the pydantic mypy plugin seems to solve this problem. https://docs.pydantic.dev/latest/integrations/mypy/

After adding this:
mypy . --ignore-missing-imports | grep "Cannot override class variable (previously declared on base class "BaseModel") with instance variable" return zero lint errors relating to overring class variaables.

@krrishdholakia
Copy link
Contributor

Thanks for this @lj-wego,

Can you confirm it passes on the list of tests the previous PR attempting to address this failed on - #3664

  1. tests/test_ratelimit.py
  2. test_organizations.py/test_organization_new
  3. Failed linting on types/completion.py, types/router.py, types.embedding.py

@lj-wego
Copy link
Contributor Author

lj-wego commented May 21, 2024

  1. tests/test_ratelimit.py

image

@lj-wego
Copy link
Contributor Author

lj-wego commented May 21, 2024

test_organizations.py/test_organization_new

took awhile to figure out what needed to be ran but managed to set up a local docker postgres, prisma migrate and ran the server, and then the test.

image

results

image

@lj-wego
Copy link
Contributor Author

lj-wego commented May 21, 2024

Failed linting on types/completion.py, types/router.py, types.embedding.py

i believe this fixes this #3670 (comment)

@lj-wego
Copy link
Contributor Author

lj-wego commented May 21, 2024

@krrishdholakia can confirm it works on my machine.

@rickyyx
Copy link

rickyyx commented May 30, 2024

Thanks! This is really cogging our CI logs. :(

@lj-wego
Copy link
Contributor Author

lj-wego commented May 31, 2024

Merged new changes and updated one pesky class Config that was introduced.

Hands tied here for the CI since:
a. i don't have most of the services API keys to properly run the full test/lint suite
b. i don't use circle ci so can't reproduce the testing workflow.

@krrishdholakia krrishdholakia merged commit deb87f7 into BerriAI:main May 31, 2024
3 checks passed
@krrishdholakia
Copy link
Contributor

Merging in - i'll let you know if there's any issues on ci/cd @lj-wego

Thank you again for your help here!

@lj-wego
Copy link
Contributor Author

lj-wego commented May 31, 2024

@krrishdholakia
i notice the CI failing and this might be the issue.

installs older pydantic
image

image

pydantic==1.10.14

@lj-wego
Copy link
Contributor Author

lj-wego commented May 31, 2024

Added a PR here to address this. Unless this is reverted 😓

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.

Clean up / Fix test warnings resulting from pydantic V2 migration
3 participants