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

@@ -9,8 +9,8 @@ from langchain_core.callbacks import (
)
from langchain_core.language_models.llms import BaseLLM, create_base_retry_decorator
from langchain_core.outputs import Generation, GenerationChunk, LLMResult
from langchain_core.pydantic_v1 import Field, SecretStr, root_validator
from langchain_core.utils import convert_to_secret_str
from langchain_core.pydantic_v1 import Field, SecretStr
from langchain_core.utils import convert_to_secret_str, pre_init
from langchain_core.utils.env import get_from_dict_or_env
@@ -61,7 +61,7 @@ class Fireworks(BaseLLM):
"""Get the namespace of the langchain object."""
return ["langchain", "llms", "fireworks"]
@root_validator()
@pre_init
def validate_environment(cls, values: Dict) -> Dict:
"""Validate that api key in environment."""
try: