From 6eae054dba55692297808a835587cd52a07b3f3f Mon Sep 17 00:00:00 2001 From: Steve Moss Date: Thu, 24 Oct 2024 11:24:16 +0100 Subject: [PATCH] community: Fix missing protected_namespaces(). --- libs/community/langchain_community/embeddings/ascend.py | 4 +++- .../langchain_community/embeddings/baidu_qianfan_endpoint.py | 4 +++- libs/community/langchain_community/embeddings/bookend.py | 4 +++- libs/community/langchain_community/embeddings/ernie.py | 4 +++- libs/community/langchain_community/embeddings/google_palm.py | 4 +++- libs/community/langchain_community/embeddings/gpt4all.py | 4 +++- .../langchain_community/embeddings/infinity_local.py | 1 + libs/community/langchain_community/embeddings/itrex.py | 1 + libs/community/langchain_community/embeddings/jina.py | 4 +++- libs/community/langchain_community/embeddings/llamacpp.py | 1 + libs/community/langchain_community/embeddings/nlpcloud.py | 4 +++- .../community/langchain_community/embeddings/optimum_intel.py | 1 + libs/community/langchain_community/embeddings/sambanova.py | 4 +++- .../langchain_community/embeddings/tensorflow_hub.py | 1 + libs/community/langchain_community/embeddings/text2vec.py | 4 +++- 15 files changed, 35 insertions(+), 10 deletions(-) diff --git a/libs/community/langchain_community/embeddings/ascend.py b/libs/community/langchain_community/embeddings/ascend.py index dd8c9c67fd94c..d01f7967491d8 100644 --- a/libs/community/langchain_community/embeddings/ascend.py +++ b/libs/community/langchain_community/embeddings/ascend.py @@ -2,7 +2,7 @@ from typing import Any, Dict, List, Optional from langchain_core.embeddings import Embeddings -from pydantic import BaseModel, model_validator +from pydantic import BaseModel, ConfigDict, model_validator class AscendEmbeddings(Embeddings, BaseModel): @@ -33,6 +33,8 @@ class AscendEmbeddings(Embeddings, BaseModel): model: Any tokenizer: Any + model_config = ConfigDict(protected_namespaces=()) + def __init__(self, *args: Any, **kwargs: Any) -> None: super().__init__(*args, **kwargs) try: diff --git a/libs/community/langchain_community/embeddings/baidu_qianfan_endpoint.py b/libs/community/langchain_community/embeddings/baidu_qianfan_endpoint.py index 14e2f35a4ea40..aaba2f3487a46 100644 --- a/libs/community/langchain_community/embeddings/baidu_qianfan_endpoint.py +++ b/libs/community/langchain_community/embeddings/baidu_qianfan_endpoint.py @@ -5,7 +5,7 @@ from langchain_core.embeddings import Embeddings from langchain_core.utils import convert_to_secret_str, get_from_dict_or_env, pre_init -from pydantic import BaseModel, Field, SecretStr +from pydantic import BaseModel, ConfigDict, Field, SecretStr logger = logging.getLogger(__name__) @@ -81,6 +81,8 @@ class QianfanEmbeddingsEndpoint(BaseModel, Embeddings): model_kwargs: Dict[str, Any] = Field(default_factory=dict) """extra params for model invoke using with `do`.""" + model_config = ConfigDict(protected_namespaces=()) + @pre_init def validate_environment(cls, values: Dict) -> Dict: """ diff --git a/libs/community/langchain_community/embeddings/bookend.py b/libs/community/langchain_community/embeddings/bookend.py index c5390e19e71f0..8e977834a47bf 100644 --- a/libs/community/langchain_community/embeddings/bookend.py +++ b/libs/community/langchain_community/embeddings/bookend.py @@ -5,7 +5,7 @@ import requests from langchain_core.embeddings import Embeddings -from pydantic import BaseModel, Field +from pydantic import BaseModel, ConfigDict, Field API_URL = "https://api.bookend.ai/" DEFAULT_TASK = "embeddings" @@ -42,6 +42,8 @@ class BookendEmbeddings(BaseModel, Embeddings): """Embeddings model ID to use.""" auth_header: dict = Field(default_factory=dict) + model_config = ConfigDict(protected_namespaces=()) + def __init__(self, **kwargs: Any): super().__init__(**kwargs) self.auth_header = {"Authorization": "Basic {}".format(self.api_token)} diff --git a/libs/community/langchain_community/embeddings/ernie.py b/libs/community/langchain_community/embeddings/ernie.py index 42a49e2c6ca6f..34758c58b4c20 100644 --- a/libs/community/langchain_community/embeddings/ernie.py +++ b/libs/community/langchain_community/embeddings/ernie.py @@ -8,7 +8,7 @@ from langchain_core.embeddings import Embeddings from langchain_core.runnables.config import run_in_executor from langchain_core.utils import get_from_dict_or_env, pre_init -from pydantic import BaseModel +from pydantic import BaseModel, ConfigDict logger = logging.getLogger(__name__) @@ -31,6 +31,8 @@ class ErnieEmbeddings(BaseModel, Embeddings): _lock = threading.Lock() + model_config = ConfigDict(protected_namespaces=()) + @pre_init def validate_environment(cls, values: Dict) -> Dict: values["ernie_api_base"] = get_from_dict_or_env( diff --git a/libs/community/langchain_community/embeddings/google_palm.py b/libs/community/langchain_community/embeddings/google_palm.py index 363214caead72..d058bc46add0d 100644 --- a/libs/community/langchain_community/embeddings/google_palm.py +++ b/libs/community/langchain_community/embeddings/google_palm.py @@ -5,7 +5,7 @@ from langchain_core.embeddings import Embeddings from langchain_core.utils import get_from_dict_or_env, pre_init -from pydantic import BaseModel +from pydantic import BaseModel, ConfigDict from tenacity import ( before_sleep_log, retry, @@ -62,6 +62,8 @@ class GooglePalmEmbeddings(BaseModel, Embeddings): show_progress_bar: bool = False """Whether to show a tqdm progress bar. Must have `tqdm` installed.""" + model_config = ConfigDict(protected_namespaces=()) + @pre_init def validate_environment(cls, values: Dict) -> Dict: """Validate api key, python package exists.""" diff --git a/libs/community/langchain_community/embeddings/gpt4all.py b/libs/community/langchain_community/embeddings/gpt4all.py index ce92ab84b6d23..5183cbb08bd84 100644 --- a/libs/community/langchain_community/embeddings/gpt4all.py +++ b/libs/community/langchain_community/embeddings/gpt4all.py @@ -1,7 +1,7 @@ from typing import Any, Dict, List, Optional from langchain_core.embeddings import Embeddings -from pydantic import BaseModel, model_validator +from pydantic import BaseModel, ConfigDict, model_validator class GPT4AllEmbeddings(BaseModel, Embeddings): @@ -28,6 +28,8 @@ class GPT4AllEmbeddings(BaseModel, Embeddings): gpt4all_kwargs: Optional[dict] = {} client: Any #: :meta private: + model_config = ConfigDict(protected_namespaces=()) + @model_validator(mode="before") @classmethod def validate_environment(cls, values: Dict) -> Any: diff --git a/libs/community/langchain_community/embeddings/infinity_local.py b/libs/community/langchain_community/embeddings/infinity_local.py index 610ccaf3e88f0..075d028c9c758 100644 --- a/libs/community/langchain_community/embeddings/infinity_local.py +++ b/libs/community/langchain_community/embeddings/infinity_local.py @@ -60,6 +60,7 @@ class InfinityEmbeddingsLocal(BaseModel, Embeddings): # LLM call kwargs model_config = ConfigDict( extra="forbid", + protected_namespaces=(), ) @model_validator(mode="after") diff --git a/libs/community/langchain_community/embeddings/itrex.py b/libs/community/langchain_community/embeddings/itrex.py index 2fcd0afae3d7c..1f9a8e0731bfd 100644 --- a/libs/community/langchain_community/embeddings/itrex.py +++ b/libs/community/langchain_community/embeddings/itrex.py @@ -120,6 +120,7 @@ def load_model(self) -> None: model_config = ConfigDict( extra="allow", + protected_namespaces=(), ) def _embed(self, inputs: Any) -> Any: diff --git a/libs/community/langchain_community/embeddings/jina.py b/libs/community/langchain_community/embeddings/jina.py index 718345f1afd23..b46ae026397e9 100644 --- a/libs/community/langchain_community/embeddings/jina.py +++ b/libs/community/langchain_community/embeddings/jina.py @@ -6,7 +6,7 @@ import requests from langchain_core.embeddings import Embeddings from langchain_core.utils import convert_to_secret_str, get_from_dict_or_env -from pydantic import BaseModel, SecretStr, model_validator +from pydantic import BaseModel, ConfigDict, SecretStr, model_validator JINA_API_URL: str = "https://api.jina.ai/v1/embeddings" @@ -46,6 +46,8 @@ class JinaEmbeddings(BaseModel, Embeddings): model_name: str = "jina-embeddings-v2-base-en" jina_api_key: Optional[SecretStr] = None + model_config = ConfigDict(protected_namespaces=()) + @model_validator(mode="before") @classmethod def validate_environment(cls, values: Dict) -> Any: diff --git a/libs/community/langchain_community/embeddings/llamacpp.py b/libs/community/langchain_community/embeddings/llamacpp.py index 86a029ea753f0..6487312fd31d0 100644 --- a/libs/community/langchain_community/embeddings/llamacpp.py +++ b/libs/community/langchain_community/embeddings/llamacpp.py @@ -63,6 +63,7 @@ class LlamaCppEmbeddings(BaseModel, Embeddings): model_config = ConfigDict( extra="forbid", + protected_namespaces=(), ) @model_validator(mode="after") diff --git a/libs/community/langchain_community/embeddings/nlpcloud.py b/libs/community/langchain_community/embeddings/nlpcloud.py index decf8ac2b803e..7e13f9cbbaf93 100644 --- a/libs/community/langchain_community/embeddings/nlpcloud.py +++ b/libs/community/langchain_community/embeddings/nlpcloud.py @@ -2,7 +2,7 @@ from langchain_core.embeddings import Embeddings from langchain_core.utils import get_from_dict_or_env, pre_init -from pydantic import BaseModel +from pydantic import BaseModel, ConfigDict class NLPCloudEmbeddings(BaseModel, Embeddings): @@ -22,6 +22,8 @@ class NLPCloudEmbeddings(BaseModel, Embeddings): gpu: bool # Define gpu as a class attribute client: Any #: :meta private: + model_config = ConfigDict(protected_namespaces=()) + def __init__( self, model_name: str = "paraphrase-multilingual-mpnet-base-v2", diff --git a/libs/community/langchain_community/embeddings/optimum_intel.py b/libs/community/langchain_community/embeddings/optimum_intel.py index 657cba32c78c4..05de5cca3a963 100644 --- a/libs/community/langchain_community/embeddings/optimum_intel.py +++ b/libs/community/langchain_community/embeddings/optimum_intel.py @@ -102,6 +102,7 @@ def load_model(self) -> None: model_config = ConfigDict( extra="allow", + protected_namespaces=(), ) def _embed(self, inputs: Any) -> Any: diff --git a/libs/community/langchain_community/embeddings/sambanova.py b/libs/community/langchain_community/embeddings/sambanova.py index 0daab18ef6620..e23760b43182c 100644 --- a/libs/community/langchain_community/embeddings/sambanova.py +++ b/libs/community/langchain_community/embeddings/sambanova.py @@ -4,7 +4,7 @@ import requests from langchain_core.embeddings import Embeddings from langchain_core.utils import get_from_dict_or_env, pre_init -from pydantic import BaseModel +from pydantic import BaseModel, ConfigDict class SambaStudioEmbeddings(BaseModel, Embeddings): @@ -64,6 +64,8 @@ class SambaStudioEmbeddings(BaseModel, Embeddings): batch_size: int = 32 """Batch size for the embedding models""" + model_config = ConfigDict(protected_namespaces=()) + @pre_init def validate_environment(cls, values: Dict) -> Dict: """Validate that api key and python package exists in environment.""" diff --git a/libs/community/langchain_community/embeddings/tensorflow_hub.py b/libs/community/langchain_community/embeddings/tensorflow_hub.py index a9c2edf419b9d..270c9f17cb36e 100644 --- a/libs/community/langchain_community/embeddings/tensorflow_hub.py +++ b/libs/community/langchain_community/embeddings/tensorflow_hub.py @@ -45,6 +45,7 @@ def __init__(self, **kwargs: Any): model_config = ConfigDict( extra="forbid", + protected_namespaces=(), ) def embed_documents(self, texts: List[str]) -> List[List[float]]: diff --git a/libs/community/langchain_community/embeddings/text2vec.py b/libs/community/langchain_community/embeddings/text2vec.py index 2d55f5585b5ea..4b8cc77192ad5 100644 --- a/libs/community/langchain_community/embeddings/text2vec.py +++ b/libs/community/langchain_community/embeddings/text2vec.py @@ -3,7 +3,7 @@ from typing import Any, List, Optional from langchain_core.embeddings import Embeddings -from pydantic import BaseModel +from pydantic import BaseModel, ConfigDict class Text2vecEmbeddings(Embeddings, BaseModel): @@ -33,6 +33,8 @@ class Text2vecEmbeddings(Embeddings, BaseModel): device: Optional[str] = None model: Any = None + model_config = ConfigDict(protected_namespaces=()) + def __init__( self, *,