Skip to content

Commit

Permalink
community[patch]: Fix missing protected_namespaces(). (#27610)
Browse files Browse the repository at this point in the history
- [x] **PR message**:
- **Description:** Fixes warning messages raised due to missing
`protected_namespaces` parameter in `ConfigDict`.
    - **Issue:** #27609
    - **Dependencies:** No dependencies
    - **Twitter handle:** @gawbul
  • Loading branch information
gawbul authored Oct 25, 2024
1 parent 7667ee1 commit 24605bc
Show file tree
Hide file tree
Showing 15 changed files with 35 additions and 10 deletions.
4 changes: 3 additions & 1 deletion libs/community/langchain_community/embeddings/ascend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -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:
"""
Expand Down
4 changes: 3 additions & 1 deletion libs/community/langchain_community/embeddings/bookend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)}
Expand Down
4 changes: 3 additions & 1 deletion libs/community/langchain_community/embeddings/ernie.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand All @@ -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(
Expand Down
4 changes: 3 additions & 1 deletion libs/community/langchain_community/embeddings/google_palm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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."""
Expand Down
4 changes: 3 additions & 1 deletion libs/community/langchain_community/embeddings/gpt4all.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class InfinityEmbeddingsLocal(BaseModel, Embeddings):
# LLM call kwargs
model_config = ConfigDict(
extra="forbid",
protected_namespaces=(),
)

@model_validator(mode="after")
Expand Down
1 change: 1 addition & 0 deletions libs/community/langchain_community/embeddings/itrex.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ def load_model(self) -> None:

model_config = ConfigDict(
extra="allow",
protected_namespaces=(),
)

def _embed(self, inputs: Any) -> Any:
Expand Down
4 changes: 3 additions & 1 deletion libs/community/langchain_community/embeddings/jina.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions libs/community/langchain_community/embeddings/llamacpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class LlamaCppEmbeddings(BaseModel, Embeddings):

model_config = ConfigDict(
extra="forbid",
protected_namespaces=(),
)

@model_validator(mode="after")
Expand Down
4 changes: 3 additions & 1 deletion libs/community/langchain_community/embeddings/nlpcloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ def load_model(self) -> None:

model_config = ConfigDict(
extra="allow",
protected_namespaces=(),
)

def _embed(self, inputs: Any) -> Any:
Expand Down
4 changes: 3 additions & 1 deletion libs/community/langchain_community/embeddings/sambanova.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]]:
Expand Down
4 changes: 3 additions & 1 deletion libs/community/langchain_community/embeddings/text2vec.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -33,6 +33,8 @@ class Text2vecEmbeddings(Embeddings, BaseModel):
device: Optional[str] = None
model: Any = None

model_config = ConfigDict(protected_namespaces=())

def __init__(
self,
*,
Expand Down

0 comments on commit 24605bc

Please sign in to comment.