mirror of
https://github.com/hwchase17/langchain.git
synced 2025-07-06 13:18:12 +00:00
community[patch]: Update @root_validators to use explicit pre=True or pre=False (#23737)
This commit is contained in:
parent
b664dbcc36
commit
46ff0f7a3c
@ -80,7 +80,7 @@ class AlephAlphaAsymmetricSemanticEmbedding(BaseModel, Embeddings):
|
||||
nice to other users
|
||||
by de-prioritizing your request below concurrent ones."""
|
||||
|
||||
@root_validator()
|
||||
@root_validator(pre=True)
|
||||
def validate_environment(cls, values: Dict) -> Dict:
|
||||
"""Validate that api key and python package exists in environment."""
|
||||
aleph_alpha_api_key = get_from_dict_or_env(
|
||||
|
@ -16,7 +16,7 @@ class AwaEmbeddings(BaseModel, Embeddings):
|
||||
client: Any #: :meta private:
|
||||
model: str = "all-mpnet-base-v2"
|
||||
|
||||
@root_validator()
|
||||
@root_validator(pre=True)
|
||||
def validate_environment(cls, values: Dict) -> Dict:
|
||||
"""Validate that awadb library is installed."""
|
||||
|
||||
|
@ -54,7 +54,7 @@ class AzureOpenAIEmbeddings(OpenAIEmbeddings):
|
||||
"""Automatically inferred from env var `OPENAI_API_VERSION` if not provided."""
|
||||
validate_base_url: bool = True
|
||||
|
||||
@root_validator()
|
||||
@root_validator(pre=True)
|
||||
def validate_environment(cls, values: Dict) -> Dict:
|
||||
"""Validate that api key and python package exists in environment."""
|
||||
# Check OPENAI_KEY for backwards compatibility.
|
||||
@ -96,8 +96,7 @@ class AzureOpenAIEmbeddings(OpenAIEmbeddings):
|
||||
# See: https://learn.microsoft.com/en-us/azure/ai-services/openai/reference#embeddings
|
||||
values["chunk_size"] = min(values["chunk_size"], 16)
|
||||
try:
|
||||
import openai
|
||||
|
||||
import openai # noqa: F401
|
||||
except ImportError:
|
||||
raise ImportError(
|
||||
"Could not import openai python package. "
|
||||
@ -137,6 +136,14 @@ class AzureOpenAIEmbeddings(OpenAIEmbeddings):
|
||||
"/deployments/" + values["deployment"]
|
||||
)
|
||||
values["deployment"] = None
|
||||
return values
|
||||
|
||||
@root_validator(pre=False, skip_on_failure=True)
|
||||
def post_init_validator(cls, values: Dict) -> Dict:
|
||||
"""Validate that the base url is set."""
|
||||
import openai
|
||||
|
||||
if is_openai_v1():
|
||||
client_params = {
|
||||
"api_version": values["openai_api_version"],
|
||||
"azure_endpoint": values["azure_endpoint"],
|
||||
|
@ -73,7 +73,7 @@ class BedrockEmbeddings(BaseModel, Embeddings):
|
||||
|
||||
extra = Extra.forbid
|
||||
|
||||
@root_validator()
|
||||
@root_validator(pre=False, skip_on_failure=True)
|
||||
def validate_environment(cls, values: Dict) -> Dict:
|
||||
"""Validate that AWS credentials to and python package exists in environment."""
|
||||
|
||||
|
@ -48,7 +48,7 @@ class ClarifaiEmbeddings(BaseModel, Embeddings):
|
||||
|
||||
extra = Extra.forbid
|
||||
|
||||
@root_validator()
|
||||
@root_validator(pre=True)
|
||||
def validate_environment(cls, values: Dict) -> Dict:
|
||||
"""Validate that we have all required info to access Clarifai
|
||||
platform and python package exists in environment."""
|
||||
|
@ -54,7 +54,7 @@ class CohereEmbeddings(BaseModel, Embeddings):
|
||||
|
||||
extra = Extra.forbid
|
||||
|
||||
@root_validator()
|
||||
@root_validator(pre=True)
|
||||
def validate_environment(cls, values: Dict) -> Dict:
|
||||
"""Validate that api key and python package exists in environment."""
|
||||
cohere_api_key = get_from_dict_or_env(
|
||||
|
Loading…
Reference in New Issue
Block a user