pydantic v2 warns about using a Config class.
But without this, pydantic v1 will raise an error:
RuntimeError: no validator found for <class 'openai.Timeout'>,
see `arbitrary_types_allowed` in Config
Putting arbitrary_types_allowed = True in the ConfigDict doesn't work in pydantic v1.
So we mostly use model_config = ConfigDict(...) and then only use the Config
class with arbitrary_types_allowed = True for pydantic v1.
in `litellm/types/router.py`
I didn't replace the ones that have `allow_arbitrary_types` because changing
those seems to break pydantic v1 compatibility.
pydantic v1 uses `root_validator` and pydantic v2 uses `model_validator`.
pydantic v2 emits a warning when `root_validator` is used. E.g.:
```
litellm/proxy/_types.py:225
/Users/abramowi/Code/OpenSource/litellm/litellm/proxy/_types.py:225:
PydanticDeprecatedSince20: Pydantic V1 style `@root_validator`
validators are deprecated.
You should migrate to Pydantic V2 style `@model_validator` validators,
see the migration guide for more details.
Deprecated in Pydantic V2.0 to be removed in V3.0.
See Pydantic V2 Migration Guide at
https://errors.pydantic.dev/2.7/migration/
@root_validator(pre=True)
```
This change eliminates those warnings with pydantic v2, while retaining
compatibility with pydantic v1.
pydantic 2.7.1 before
```
$ env -i PATH=$PATH poetry run pytest litellm/tests/test_proxy_server.py
...
litellm/proxy/_types.py:225
/Users/abramowi/Code/OpenSource/litellm/litellm/proxy/_types.py:225: PydanticDeprecatedSince20: Pydantic V1 style `@root_validator` validators are deprecated. You should migrate to Pydantic V2 style `@model_validator` validators, see the migration guide for more details. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.7/migration/
@root_validator(pre=True)
...
========================== 10 passed, 2 skipped, 39 warnings in 8.67s ===========================
```
pydantic 2.7.1 after
```
$ env -i PATH=$PATH poetry run pytest litellm/tests/test_proxy_server.py
...
========================== 10 passed, 2 skipped, 27 warnings in 9.85s ===========================
```
pydantic 1.10.5 after
```
$ poetry run pip install 'pydantic<2'
...
Successfully installed pydantic-1.10.15
$ env -i PATH=$PATH poetry run pytest litellm/tests/test_proxy_server.py
...
=========================== 10 passed, 2 skipped, 1 warning in 8.13s ============================
```