community[patch]: Use get_fields adapter for pydantic (#25191)

Change all usages of __fields__ with get_fields adapter merged into
langchain_core.

Code mod generated using the following grit pattern:

```
engine marzano(0.1)
language python


`$X.__fields__` => `get_fields($X)` where {
    add_import(source="langchain_core.utils.pydantic", name="get_fields")
}
```
This commit is contained in:
Eugene Yurtsev
2024-08-08 14:43:09 -04:00
committed by GitHub
parent 663638d6a8
commit 98779797fe
24 changed files with 51 additions and 28 deletions

View File

@@ -6,6 +6,7 @@ from typing import Any, Union
import yaml
from langchain_core.language_models.llms import BaseLLM
from langchain_core.utils.pydantic import get_fields
from langchain_community.llms import get_type_to_cls_dict
@@ -26,7 +27,7 @@ def load_llm_from_config(config: dict, **kwargs: Any) -> BaseLLM:
llm_cls = type_to_cls_dict[config_type]()
load_kwargs = {}
if _ALLOW_DANGEROUS_DESERIALIZATION_ARG in llm_cls.__fields__:
if _ALLOW_DANGEROUS_DESERIALIZATION_ARG in get_fields(llm_cls):
load_kwargs[_ALLOW_DANGEROUS_DESERIALIZATION_ARG] = kwargs.get(
_ALLOW_DANGEROUS_DESERIALIZATION_ARG, False
)