core[minor],community[minor]: Upgrade all @root_validator() to @pre_init (#23841)

This PR introduces a @pre_init decorator that's a @root_validator(pre=True) but with all the defaults populated!
This commit is contained in:
Eugene Yurtsev
2024-07-08 16:09:29 -04:00
committed by GitHub
parent f152d6ed3d
commit 2c180d645e
114 changed files with 439 additions and 276 deletions

View File

@@ -1,12 +1,18 @@
# flake8: noqa
from langchain_core.utils import pre_init
from typing import Any, AsyncIterator, Dict, Iterator, List, Optional, Union
from langchain_core.utils import pre_init
from langchain_core.pydantic_v1 import root_validator
from langchain_core.utils import pre_init
from langchain_core.callbacks import (
AsyncCallbackManagerForLLMRun,
CallbackManagerForLLMRun,
)
from langchain_core.utils import pre_init
from langchain_core.language_models.llms import LLM
from langchain_core.utils import pre_init
from langchain_community.llms.utils import enforce_stop_tokens
from langchain_core.utils import pre_init
from langchain_core.outputs import GenerationChunk
@@ -55,7 +61,7 @@ class DeepSparse(LLM):
"""Return type of llm."""
return "deepsparse"
@root_validator()
@pre_init
def validate_environment(cls, values: Dict) -> Dict:
"""Validate that ``deepsparse`` package is installed."""
try: