From d24b82357f055a9ee64365674da629adf8b6be74 Mon Sep 17 00:00:00 2001 From: Eugene Yurtsev Date: Wed, 31 Jul 2024 14:13:44 -0400 Subject: [PATCH] community[patch]: Add missing annotations (#24890) This PR adds annotations in comunity package. Annotations are only strictly needed in subclasses of BaseModel for pydantic 2 compatibility. This PR adds some unnecessary annotations, but they're not bad to have regardless for documentation pages. --- .../callbacks/upstash_ratelimit_callback.py | 2 +- .../chains/pebblo_retrieval/base.py | 2 +- .../chat_models/kinetica.py | 4 ++-- .../chat_models/oci_generative_ai.py | 4 ++-- .../document_compressors/llmlingua_filter.py | 6 +++--- .../document_loaders/acreom.py | 6 ++++-- .../document_loaders/docugami.py | 4 ++-- .../document_loaders/hugging_face_model.py | 4 ++-- .../document_loaders/obsidian.py | 18 +++++++++++------- .../document_loaders/onenote.py | 2 +- .../document_loaders/parsers/language/cobol.py | 8 ++++---- .../langchain_community/embeddings/ernie.py | 2 +- .../langchain_community/graphs/age_graph.py | 4 ++-- .../langchain_community/llms/moonshot.py | 4 ++-- ...i_data_science_model_deployment_endpoint.py | 2 +- .../llms/oci_generative_ai.py | 4 ++-- .../langchain_community/llms/sambanova.py | 2 +- .../langchain_community/llms/solar.py | 2 +- .../query_constructors/supabase.py | 2 +- .../langchain_community/tools/bearly/tool.py | 4 ++-- .../langchain_community/tools/zenguard/tool.py | 6 +++--- .../langchain_community/utilities/portkey.py | 2 +- .../langchain_community/utilities/redis.py | 2 +- .../langchain_community/vectorstores/atlas.py | 2 +- .../langchain_community/vectorstores/awadb.py | 2 +- .../langchain_community/vectorstores/bagel.py | 2 +- .../langchain_community/vectorstores/chroma.py | 2 +- .../vectorstores/couchbase.py | 8 ++++---- .../vectorstores/deeplake.py | 2 +- .../vectorstores/epsilla.py | 6 +++--- .../vectorstores/hanavector.py | 3 ++- .../vectorstores/manticore_search.py | 2 +- .../langchain_community/vectorstores/qdrant.py | 4 ++-- .../langchain_community/vectorstores/semadb.py | 2 +- .../document_loaders/test_quip.py | 4 ++-- .../llms/test_azureml_endpoint.py | 8 ++++---- .../tools/nuclia/test_nuclia.py | 8 ++++---- .../unit_tests/chat_models/test_kinetica.py | 2 +- .../document_loaders/test_confluence.py | 8 ++++---- .../unit_tests/document_loaders/test_lakefs.py | 12 ++++++------ .../document_loaders/test_psychic.py | 6 +++--- .../document_loaders/test_rspace_loader.py | 6 +++--- .../unit_tests/embeddings/test_gradient_ai.py | 2 +- .../tests/unit_tests/embeddings/test_ollama.py | 2 +- 44 files changed, 98 insertions(+), 91 deletions(-) diff --git a/libs/community/langchain_community/callbacks/upstash_ratelimit_callback.py b/libs/community/langchain_community/callbacks/upstash_ratelimit_callback.py index 068bf9dc05a..012350aca63 100644 --- a/libs/community/langchain_community/callbacks/upstash_ratelimit_callback.py +++ b/libs/community/langchain_community/callbacks/upstash_ratelimit_callback.py @@ -58,7 +58,7 @@ class UpstashRatelimitHandler(BaseCallbackHandler): every time you invoke. """ - raise_error = True + raise_error: bool = True _checked: bool = False def __init__( diff --git a/libs/community/langchain_community/chains/pebblo_retrieval/base.py b/libs/community/langchain_community/chains/pebblo_retrieval/base.py index 5dcc15775d7..5722de0ddda 100644 --- a/libs/community/langchain_community/chains/pebblo_retrieval/base.py +++ b/libs/community/langchain_community/chains/pebblo_retrieval/base.py @@ -76,7 +76,7 @@ class PebbloRetrievalQA(Chain): """Classifier endpoint.""" classifier_location: str = "local" #: :meta private: """Classifier location. It could be either of 'local' or 'pebblo-cloud'.""" - _discover_sent = False #: :meta private: + _discover_sent: bool = False #: :meta private: """Flag to check if discover payload has been sent.""" _prompt_sent: bool = False #: :meta private: """Flag to check if prompt payload has been sent.""" diff --git a/libs/community/langchain_community/chat_models/kinetica.py b/libs/community/langchain_community/chat_models/kinetica.py index 3724d82b38c..3c9b800c84b 100644 --- a/libs/community/langchain_community/chat_models/kinetica.py +++ b/libs/community/langchain_community/chat_models/kinetica.py @@ -9,7 +9,7 @@ import os import re from importlib.metadata import version from pathlib import Path -from typing import TYPE_CHECKING, Any, Dict, List, Optional, cast +from typing import TYPE_CHECKING, Any, Dict, List, Optional, Pattern, cast from langchain_core.utils import pre_init @@ -164,7 +164,7 @@ class _KineticaLlmFileContextParser: """Parser for Kinetica LLM context datafiles.""" # parse line into a dict containing role and content - PARSER = re.compile(r"^<\|(?P\w+)\|>\W*(?P.*)$", re.DOTALL) + PARSER: Pattern = re.compile(r"^<\|(?P\w+)\|>\W*(?P.*)$", re.DOTALL) @classmethod def _removesuffix(cls, text: str, suffix: str) -> str: diff --git a/libs/community/langchain_community/chat_models/oci_generative_ai.py b/libs/community/langchain_community/chat_models/oci_generative_ai.py index 4edbe04456e..21a94e7cbde 100644 --- a/libs/community/langchain_community/chat_models/oci_generative_ai.py +++ b/libs/community/langchain_community/chat_models/oci_generative_ai.py @@ -135,7 +135,7 @@ class Provider(ABC): class CohereProvider(Provider): - stop_sequence_key = "stop_sequences" + stop_sequence_key: str = "stop_sequences" def __init__(self) -> None: from oci.generative_ai_inference import models @@ -364,7 +364,7 @@ class CohereProvider(Provider): class MetaProvider(Provider): - stop_sequence_key = "stop" + stop_sequence_key: str = "stop" def __init__(self) -> None: from oci.generative_ai_inference import models diff --git a/libs/community/langchain_community/document_compressors/llmlingua_filter.py b/libs/community/langchain_community/document_compressors/llmlingua_filter.py index 8a5dbf02ebd..9749dcd73ce 100644 --- a/libs/community/langchain_community/document_compressors/llmlingua_filter.py +++ b/libs/community/langchain_community/document_compressors/llmlingua_filter.py @@ -1,7 +1,7 @@ # LLM Lingua Document Compressor import re -from typing import Any, Dict, List, Optional, Sequence, Tuple +from typing import Any, Dict, List, Optional, Pattern, Sequence, Tuple from langchain_core.callbacks import Callbacks from langchain_core.documents import Document @@ -24,8 +24,8 @@ class LLMLinguaCompressor(BaseDocumentCompressor): # Pattern to match ref tags at the beginning or end of the string, # allowing for malformed tags - _pattern_beginning = re.compile(r"\A(?:<#)?(?:ref)?(\d+)(?:#>?)?") - _pattern_ending = re.compile(r"(?:<#)?(?:ref)?(\d+)(?:#>?)?\Z") + _pattern_beginning: Pattern = re.compile(r"\A(?:<#)?(?:ref)?(\d+)(?:#>?)?") + _pattern_ending: Pattern = re.compile(r"(?:<#)?(?:ref)?(\d+)(?:#>?)?\Z") model_name: str = "NousResearch/Llama-2-7b-hf" """The hugging face model to use""" diff --git a/libs/community/langchain_community/document_loaders/acreom.py b/libs/community/langchain_community/document_loaders/acreom.py index 89aff5d1731..b5656728b60 100644 --- a/libs/community/langchain_community/document_loaders/acreom.py +++ b/libs/community/langchain_community/document_loaders/acreom.py @@ -1,6 +1,6 @@ import re from pathlib import Path -from typing import Iterator, Union +from typing import Iterator, Pattern, Union from langchain_core.documents import Document @@ -10,7 +10,9 @@ from langchain_community.document_loaders.base import BaseLoader class AcreomLoader(BaseLoader): """Load `acreom` vault from a directory.""" - FRONT_MATTER_REGEX = re.compile(r"^---\n(.*?)\n---\n", re.MULTILINE | re.DOTALL) + FRONT_MATTER_REGEX: Pattern = re.compile( + r"^---\n(.*?)\n---\n", re.MULTILINE | re.DOTALL + ) """Regex to match front matter metadata in markdown files.""" def __init__( diff --git a/libs/community/langchain_community/document_loaders/docugami.py b/libs/community/langchain_community/document_loaders/docugami.py index 7082b219652..c1bdd78965f 100644 --- a/libs/community/langchain_community/document_loaders/docugami.py +++ b/libs/community/langchain_community/document_loaders/docugami.py @@ -44,13 +44,13 @@ class DocugamiLoader(BaseLoader, BaseModel): access_token: Optional[str] = os.environ.get("DOCUGAMI_API_KEY") """The Docugami API access token to use.""" - max_text_length = 4096 + max_text_length: int = 4096 """Max length of chunk text returned.""" min_text_length: int = 32 """Threshold under which chunks are appended to next to avoid over-chunking.""" - max_metadata_length = 512 + max_metadata_length: int = 512 """Max length of metadata text returned.""" include_xml_tags: bool = False diff --git a/libs/community/langchain_community/document_loaders/hugging_face_model.py b/libs/community/langchain_community/document_loaders/hugging_face_model.py index 4486a49a2e9..2bd74aa2e92 100644 --- a/libs/community/langchain_community/document_loaders/hugging_face_model.py +++ b/libs/community/langchain_community/document_loaders/hugging_face_model.py @@ -36,8 +36,8 @@ class HuggingFaceModelLoader(BaseLoader): print(doc.metadata) # Metadata of the model """ - BASE_URL = "https://huggingface.co/api/models" - README_BASE_URL = "https://huggingface.co/{model_id}/raw/main/README.md" + BASE_URL: str = "https://huggingface.co/api/models" + README_BASE_URL: str = "https://huggingface.co/{model_id}/raw/main/README.md" def __init__( self, diff --git a/libs/community/langchain_community/document_loaders/obsidian.py b/libs/community/langchain_community/document_loaders/obsidian.py index ed5ce974cbd..703b743a0c2 100644 --- a/libs/community/langchain_community/document_loaders/obsidian.py +++ b/libs/community/langchain_community/document_loaders/obsidian.py @@ -2,7 +2,7 @@ import functools import logging import re from pathlib import Path -from typing import Any, Dict, Iterator, Union +from typing import Any, Dict, Iterator, Pattern, Union import yaml from langchain_core.documents import Document @@ -15,12 +15,16 @@ logger = logging.getLogger(__name__) class ObsidianLoader(BaseLoader): """Load `Obsidian` files from directory.""" - FRONT_MATTER_REGEX = re.compile(r"^---\n(.*?)\n---\n", re.DOTALL) - TEMPLATE_VARIABLE_REGEX = re.compile(r"{{(.*?)}}", re.DOTALL) - TAG_REGEX = re.compile(r"[^\S\/]#([a-zA-Z_]+[-_/\w]*)") - DATAVIEW_LINE_REGEX = re.compile(r"^\s*(\w+)::\s*(.*)$", re.MULTILINE) - DATAVIEW_INLINE_BRACKET_REGEX = re.compile(r"\[(\w+)::\s*(.*)\]", re.MULTILINE) - DATAVIEW_INLINE_PAREN_REGEX = re.compile(r"\((\w+)::\s*(.*)\)", re.MULTILINE) + FRONT_MATTER_REGEX: Pattern = re.compile(r"^---\n(.*?)\n---\n", re.DOTALL) + TEMPLATE_VARIABLE_REGEX: Pattern = re.compile(r"{{(.*?)}}", re.DOTALL) + TAG_REGEX: Pattern = re.compile(r"[^\S\/]#([a-zA-Z_]+[-_/\w]*)") + DATAVIEW_LINE_REGEX: Pattern = re.compile(r"^\s*(\w+)::\s*(.*)$", re.MULTILINE) + DATAVIEW_INLINE_BRACKET_REGEX: Pattern = re.compile( + r"\[(\w+)::\s*(.*)\]", re.MULTILINE + ) + DATAVIEW_INLINE_PAREN_REGEX: Pattern = re.compile( + r"\((\w+)::\s*(.*)\)", re.MULTILINE + ) def __init__( self, diff --git a/libs/community/langchain_community/document_loaders/onenote.py b/libs/community/langchain_community/document_loaders/onenote.py index 0ecc1e1da7e..33d83f10ac0 100644 --- a/libs/community/langchain_community/document_loaders/onenote.py +++ b/libs/community/langchain_community/document_loaders/onenote.py @@ -39,7 +39,7 @@ class OneNoteLoader(BaseLoader, BaseModel): """Personal access token""" onenote_api_base_url: str = "https://graph.microsoft.com/v1.0/me/onenote" """URL of Microsoft Graph API for OneNote""" - authority_url = "https://login.microsoftonline.com/consumers/" + authority_url: str = "https://login.microsoftonline.com/consumers/" """A URL that identifies a token authority""" token_path: FilePath = Path.home() / ".credentials" / "onenote_graph_token.txt" """Path to the file where the access token is stored""" diff --git a/libs/community/langchain_community/document_loaders/parsers/language/cobol.py b/libs/community/langchain_community/document_loaders/parsers/language/cobol.py index 3b33ab6d956..2b598ba2702 100644 --- a/libs/community/langchain_community/document_loaders/parsers/language/cobol.py +++ b/libs/community/langchain_community/document_loaders/parsers/language/cobol.py @@ -1,5 +1,5 @@ import re -from typing import Callable, List +from typing import Callable, List, Pattern from langchain_community.document_loaders.parsers.language.code_segmenter import ( CodeSegmenter, @@ -9,11 +9,11 @@ from langchain_community.document_loaders.parsers.language.code_segmenter import class CobolSegmenter(CodeSegmenter): """Code segmenter for `COBOL`.""" - PARAGRAPH_PATTERN = re.compile(r"^[A-Z0-9\-]+(\s+.*)?\.$", re.IGNORECASE) - DIVISION_PATTERN = re.compile( + PARAGRAPH_PATTERN: Pattern = re.compile(r"^[A-Z0-9\-]+(\s+.*)?\.$", re.IGNORECASE) + DIVISION_PATTERN: Pattern = re.compile( r"^\s*(IDENTIFICATION|DATA|PROCEDURE|ENVIRONMENT)\s+DIVISION.*$", re.IGNORECASE ) - SECTION_PATTERN = re.compile(r"^\s*[A-Z0-9\-]+\s+SECTION.$", re.IGNORECASE) + SECTION_PATTERN: Pattern = re.compile(r"^\s*[A-Z0-9\-]+\s+SECTION.$", re.IGNORECASE) def __init__(self, code: str): super().__init__(code) diff --git a/libs/community/langchain_community/embeddings/ernie.py b/libs/community/langchain_community/embeddings/ernie.py index 66888bbc68a..c640680f9c8 100644 --- a/libs/community/langchain_community/embeddings/ernie.py +++ b/libs/community/langchain_community/embeddings/ernie.py @@ -27,7 +27,7 @@ class ErnieEmbeddings(BaseModel, Embeddings): chunk_size: int = 16 - model_name = "ErnieBot-Embedding-V1" + model_name: str = "ErnieBot-Embedding-V1" _lock = threading.Lock() diff --git a/libs/community/langchain_community/graphs/age_graph.py b/libs/community/langchain_community/graphs/age_graph.py index ea6e75e5ee7..a64113856d5 100644 --- a/libs/community/langchain_community/graphs/age_graph.py +++ b/libs/community/langchain_community/graphs/age_graph.py @@ -3,7 +3,7 @@ from __future__ import annotations import json import re from hashlib import md5 -from typing import TYPE_CHECKING, Any, Dict, List, NamedTuple, Tuple, Union +from typing import TYPE_CHECKING, Any, Dict, List, NamedTuple, Pattern, Tuple, Union from langchain_community.graphs.graph_document import GraphDocument from langchain_community.graphs.graph_store import GraphStore @@ -63,7 +63,7 @@ class AGEGraph(GraphStore): } # precompiled regex for checking chars in graph labels - label_regex = re.compile("[^0-9a-zA-Z]+") + label_regex: Pattern = re.compile("[^0-9a-zA-Z]+") def __init__( self, graph_name: str, conf: Dict[str, Any], create: bool = True diff --git a/libs/community/langchain_community/llms/moonshot.py b/libs/community/langchain_community/llms/moonshot.py index 0370db3a242..3d916d1b7f1 100644 --- a/libs/community/langchain_community/llms/moonshot.py +++ b/libs/community/langchain_community/llms/moonshot.py @@ -39,9 +39,9 @@ class MoonshotCommon(BaseModel): """Moonshot API key. Get it here: https://platform.moonshot.cn/console/api-keys""" model_name: str = Field(default="moonshot-v1-8k", alias="model") """Model name. Available models listed here: https://platform.moonshot.cn/pricing""" - max_tokens = 1024 + max_tokens: int = 1024 """Maximum number of tokens to generate.""" - temperature = 0.3 + temperature: float = 0.3 """Temperature parameter (higher values make the model more creative).""" class Config: diff --git a/libs/community/langchain_community/llms/oci_data_science_model_deployment_endpoint.py b/libs/community/langchain_community/llms/oci_data_science_model_deployment_endpoint.py index 0c1178d29c9..972d2453026 100644 --- a/libs/community/langchain_community/llms/oci_data_science_model_deployment_endpoint.py +++ b/libs/community/langchain_community/llms/oci_data_science_model_deployment_endpoint.py @@ -244,7 +244,7 @@ class OCIModelDeploymentTGI(OCIModelDeploymentLLM): """Watermarking with `A Watermark for Large Language Models `_. Defaults to True.""" - return_full_text = False + return_full_text: bool = False """Whether to prepend the prompt to the generated text. Defaults to False.""" @property diff --git a/libs/community/langchain_community/llms/oci_generative_ai.py b/libs/community/langchain_community/llms/oci_generative_ai.py index 3c4feb1aa5b..0084e47d330 100644 --- a/libs/community/langchain_community/llms/oci_generative_ai.py +++ b/libs/community/langchain_community/llms/oci_generative_ai.py @@ -26,7 +26,7 @@ class Provider(ABC): class CohereProvider(Provider): - stop_sequence_key = "stop_sequences" + stop_sequence_key: str = "stop_sequences" def __init__(self) -> None: from oci.generative_ai_inference import models @@ -38,7 +38,7 @@ class CohereProvider(Provider): class MetaProvider(Provider): - stop_sequence_key = "stop" + stop_sequence_key: str = "stop" def __init__(self) -> None: from oci.generative_ai_inference import models diff --git a/libs/community/langchain_community/llms/sambanova.py b/libs/community/langchain_community/llms/sambanova.py index 35a10a96397..24c98c83f74 100644 --- a/libs/community/langchain_community/llms/sambanova.py +++ b/libs/community/langchain_community/llms/sambanova.py @@ -16,7 +16,7 @@ class SVEndpointHandler: :param str host_url: Base URL of the DaaS API service """ - API_BASE_PATH = "/api/predict" + API_BASE_PATH: str = "/api/predict" def __init__(self, host_url: str): """ diff --git a/libs/community/langchain_community/llms/solar.py b/libs/community/langchain_community/llms/solar.py index 65dfdc58ed5..4afc6bd97e2 100644 --- a/libs/community/langchain_community/llms/solar.py +++ b/libs/community/langchain_community/llms/solar.py @@ -41,7 +41,7 @@ class SolarCommon(BaseModel): model_name: str = Field(default="solar-1-mini-chat", alias="model") """Model name. Available models listed here: https://console.upstage.ai/services/solar""" max_tokens: int = Field(default=1024) - temperature = 0.3 + temperature: float = 0.3 class Config: allow_population_by_field_name = True diff --git a/libs/community/langchain_community/query_constructors/supabase.py b/libs/community/langchain_community/query_constructors/supabase.py index 63794cf3787..8910b3a9d88 100644 --- a/libs/community/langchain_community/query_constructors/supabase.py +++ b/libs/community/langchain_community/query_constructors/supabase.py @@ -27,7 +27,7 @@ class SupabaseVectorTranslator(Visitor): ] """Subset of allowed logical comparators.""" - metadata_column = "metadata" + metadata_column: str = "metadata" def _map_comparator(self, comparator: Comparator) -> str: """ diff --git a/libs/community/langchain_community/tools/bearly/tool.py b/libs/community/langchain_community/tools/bearly/tool.py index cd20e80a375..6a91f39ed43 100644 --- a/libs/community/langchain_community/tools/bearly/tool.py +++ b/libs/community/langchain_community/tools/bearly/tool.py @@ -74,8 +74,8 @@ class BearlyInterpreterTool: """Tool for evaluating python code in a sandbox environment.""" api_key: str - endpoint = "https://exec.bearly.ai/v1/interpreter" - name = "bearly_interpreter" + endpoint: str = "https://exec.bearly.ai/v1/interpreter" + name: str = "bearly_interpreter" args_schema: Type[BaseModel] = BearlyInterpreterToolArguments files: Dict[str, FileInfo] = {} diff --git a/libs/community/langchain_community/tools/zenguard/tool.py b/libs/community/langchain_community/tools/zenguard/tool.py index 1bb2a8fe05b..f7ddbc4defd 100644 --- a/libs/community/langchain_community/tools/zenguard/tool.py +++ b/libs/community/langchain_community/tools/zenguard/tool.py @@ -51,12 +51,12 @@ class ZenGuardTool(BaseTool): "ZenGuard AI integration package. ZenGuard AI - the fastest GenAI guardrails." ) args_schema = ZenGuardInput - return_direct = True + return_direct: bool = True zenguard_api_key: Optional[str] = Field(default=None) - _ZENGUARD_API_URL_ROOT = "https://api.zenguard.ai/" - _ZENGUARD_API_KEY_ENV_NAME = "ZENGUARD_API_KEY" + _ZENGUARD_API_URL_ROOT: str = "https://api.zenguard.ai/" + _ZENGUARD_API_KEY_ENV_NAME: str = "ZENGUARD_API_KEY" @validator("zenguard_api_key", pre=True, always=True, check_fields=False) def set_api_key(cls, v: str) -> str: diff --git a/libs/community/langchain_community/utilities/portkey.py b/libs/community/langchain_community/utilities/portkey.py index bf9044c4f15..dbaf41840f0 100644 --- a/libs/community/langchain_community/utilities/portkey.py +++ b/libs/community/langchain_community/utilities/portkey.py @@ -11,7 +11,7 @@ class Portkey: Default: "https://api.portkey.ai/v1/proxy" """ - base = "https://api.portkey.ai/v1/proxy" + base: str = "https://api.portkey.ai/v1/proxy" @staticmethod def Config( diff --git a/libs/community/langchain_community/utilities/redis.py b/libs/community/langchain_community/utilities/redis.py index 3840c7a63d5..09aa0d27446 100644 --- a/libs/community/langchain_community/utilities/redis.py +++ b/libs/community/langchain_community/utilities/redis.py @@ -28,7 +28,7 @@ class TokenEscaper: # Characters that RediSearch requires us to escape during queries. # Source: https://redis.io/docs/stack/search/reference/escaping/#the-rules-of-text-field-tokenization - DEFAULT_ESCAPED_CHARS = r"[,.<>{}\[\]\\\"\':;!@#$%^&*()\-+=~\/ ]" + DEFAULT_ESCAPED_CHARS: str = r"[,.<>{}\[\]\\\"\':;!@#$%^&*()\-+=~\/ ]" def __init__(self, escape_chars_re: Optional[Pattern] = None): if escape_chars_re: diff --git a/libs/community/langchain_community/vectorstores/atlas.py b/libs/community/langchain_community/vectorstores/atlas.py index b5e6b3e7899..2a4034f92d2 100644 --- a/libs/community/langchain_community/vectorstores/atlas.py +++ b/libs/community/langchain_community/vectorstores/atlas.py @@ -29,7 +29,7 @@ class AtlasDB(VectorStore): vectorstore = AtlasDB("my_project", embeddings.embed_query) """ - _ATLAS_DEFAULT_ID_FIELD = "atlas_id" + _ATLAS_DEFAULT_ID_FIELD: str = "atlas_id" def __init__( self, diff --git a/libs/community/langchain_community/vectorstores/awadb.py b/libs/community/langchain_community/vectorstores/awadb.py index 96555558edd..f07100500f7 100644 --- a/libs/community/langchain_community/vectorstores/awadb.py +++ b/libs/community/langchain_community/vectorstores/awadb.py @@ -21,7 +21,7 @@ DEFAULT_TOPN = 4 class AwaDB(VectorStore): """`AwaDB` vector store.""" - _DEFAULT_TABLE_NAME = "langchain_awadb" + _DEFAULT_TABLE_NAME: str = "langchain_awadb" def __init__( self, diff --git a/libs/community/langchain_community/vectorstores/bagel.py b/libs/community/langchain_community/vectorstores/bagel.py index 6af66861384..9023642978c 100644 --- a/libs/community/langchain_community/vectorstores/bagel.py +++ b/libs/community/langchain_community/vectorstores/bagel.py @@ -53,7 +53,7 @@ class Bagel(VectorStore): vectorstore = Bagel(cluster_name="langchain_store") """ - _LANGCHAIN_DEFAULT_CLUSTER_NAME = "langchain" + _LANGCHAIN_DEFAULT_CLUSTER_NAME: str = "langchain" def __init__( self, diff --git a/libs/community/langchain_community/vectorstores/chroma.py b/libs/community/langchain_community/vectorstores/chroma.py index 71a30c98788..5f1c171088d 100644 --- a/libs/community/langchain_community/vectorstores/chroma.py +++ b/libs/community/langchain_community/vectorstores/chroma.py @@ -66,7 +66,7 @@ class Chroma(VectorStore): vectorstore = Chroma("langchain_store", embeddings) """ - _LANGCHAIN_DEFAULT_COLLECTION_NAME = "langchain" + _LANGCHAIN_DEFAULT_COLLECTION_NAME: str = "langchain" def __init__( self, diff --git a/libs/community/langchain_community/vectorstores/couchbase.py b/libs/community/langchain_community/vectorstores/couchbase.py index d002bfc4798..7bd5d727cc1 100644 --- a/libs/community/langchain_community/vectorstores/couchbase.py +++ b/libs/community/langchain_community/vectorstores/couchbase.py @@ -60,10 +60,10 @@ class CouchbaseVectorStore(VectorStore): """ # Default batch size - DEFAULT_BATCH_SIZE = 100 - _metadata_key = "metadata" - _default_text_key = "text" - _default_embedding_key = "embedding" + DEFAULT_BATCH_SIZE: int = 100 + _metadata_key: str = "metadata" + _default_text_key: str = "text" + _default_embedding_key: str = "embedding" def _check_bucket_exists(self) -> bool: """Check if the bucket exists in the linked Couchbase cluster""" diff --git a/libs/community/langchain_community/vectorstores/deeplake.py b/libs/community/langchain_community/vectorstores/deeplake.py index 904f13f9110..832ac785c82 100644 --- a/libs/community/langchain_community/vectorstores/deeplake.py +++ b/libs/community/langchain_community/vectorstores/deeplake.py @@ -51,7 +51,7 @@ class DeepLake(VectorStore): vectorstore = DeepLake("langchain_store", embeddings.embed_query) """ - _LANGCHAIN_DEFAULT_DEEPLAKE_PATH = "./deeplake/" + _LANGCHAIN_DEFAULT_DEEPLAKE_PATH: str = "./deeplake/" _valid_search_kwargs = ["lambda_mult"] def __init__( diff --git a/libs/community/langchain_community/vectorstores/epsilla.py b/libs/community/langchain_community/vectorstores/epsilla.py index a6dd12dbd46..011e3d5ab26 100644 --- a/libs/community/langchain_community/vectorstores/epsilla.py +++ b/libs/community/langchain_community/vectorstores/epsilla.py @@ -45,9 +45,9 @@ class Epsilla(VectorStore): epsilla = Epsilla(client, embeddings, db_path, db_name) """ - _LANGCHAIN_DEFAULT_DB_NAME = "langchain_store" - _LANGCHAIN_DEFAULT_DB_PATH = "/tmp/langchain-epsilla" - _LANGCHAIN_DEFAULT_TABLE_NAME = "langchain_collection" + _LANGCHAIN_DEFAULT_DB_NAME: str = "langchain_store" + _LANGCHAIN_DEFAULT_DB_PATH: str = "/tmp/langchain-epsilla" + _LANGCHAIN_DEFAULT_TABLE_NAME: str = "langchain_collection" def __init__( self, diff --git a/libs/community/langchain_community/vectorstores/hanavector.py b/libs/community/langchain_community/vectorstores/hanavector.py index c38e80f1833..07ced73afe9 100644 --- a/libs/community/langchain_community/vectorstores/hanavector.py +++ b/libs/community/langchain_community/vectorstores/hanavector.py @@ -13,6 +13,7 @@ from typing import ( Iterable, List, Optional, + Pattern, Tuple, Type, ) @@ -223,7 +224,7 @@ class HanaDB(VectorStore): return embedding # Compile pattern only once, for better performance - _compiled_pattern = re.compile("^[_a-zA-Z][_a-zA-Z0-9]*$") + _compiled_pattern: Pattern = re.compile("^[_a-zA-Z][_a-zA-Z0-9]*$") @staticmethod def _sanitize_metadata_keys(metadata: dict) -> dict: diff --git a/libs/community/langchain_community/vectorstores/manticore_search.py b/libs/community/langchain_community/vectorstores/manticore_search.py index edafb8bebdb..f92d058b01b 100644 --- a/libs/community/langchain_community/vectorstores/manticore_search.py +++ b/libs/community/langchain_community/vectorstores/manticore_search.py @@ -48,7 +48,7 @@ class ManticoreSearchSettings(BaseSettings): hnsw_m: int = 16 # The default is 16. # An optional setting that defines a construction time/accuracy trade-off. - hnsw_ef_construction = 100 + hnsw_ef_construction: int = 100 def get_connection_string(self) -> str: return self.proto + "://" + self.host + ":" + str(self.port) diff --git a/libs/community/langchain_community/vectorstores/qdrant.py b/libs/community/langchain_community/vectorstores/qdrant.py index 6d02332cebd..66f296225e4 100644 --- a/libs/community/langchain_community/vectorstores/qdrant.py +++ b/libs/community/langchain_community/vectorstores/qdrant.py @@ -85,8 +85,8 @@ class Qdrant(VectorStore): qdrant = Qdrant(client, collection_name, embedding_function) """ - CONTENT_KEY = "page_content" - METADATA_KEY = "metadata" + CONTENT_KEY: str = "page_content" + METADATA_KEY: str = "metadata" VECTOR_NAME = None def __init__( diff --git a/libs/community/langchain_community/vectorstores/semadb.py b/libs/community/langchain_community/vectorstores/semadb.py index f80c046a222..b54f832cee6 100644 --- a/libs/community/langchain_community/vectorstores/semadb.py +++ b/libs/community/langchain_community/vectorstores/semadb.py @@ -25,7 +25,7 @@ class SemaDB(VectorStore): """ - HOST = "semadb.p.rapidapi.com" + HOST: str = "semadb.p.rapidapi.com" BASE_URL = "https://" + HOST def __init__( diff --git a/libs/community/tests/integration_tests/document_loaders/test_quip.py b/libs/community/tests/integration_tests/document_loaders/test_quip.py index aea0056db86..42c1404cc15 100644 --- a/libs/community/tests/integration_tests/document_loaders/test_quip.py +++ b/libs/community/tests/integration_tests/document_loaders/test_quip.py @@ -23,9 +23,9 @@ def mock_quip(): # type: ignore @pytest.mark.requires("quip_api") class TestQuipLoader: - API_URL = "https://example-api.quip.com" + API_URL: str = "https://example-api.quip.com" DOC_URL_PREFIX = ("https://example.quip.com",) - ACCESS_TOKEN = "api_token" + ACCESS_TOKEN: str = "api_token" MOCK_FOLDER_IDS = ["ABC"] MOCK_THREAD_IDS = ["ABC", "DEF"] diff --git a/libs/community/tests/integration_tests/llms/test_azureml_endpoint.py b/libs/community/tests/integration_tests/llms/test_azureml_endpoint.py index d6c0a9993d7..cda463d719c 100644 --- a/libs/community/tests/integration_tests/llms/test_azureml_endpoint.py +++ b/libs/community/tests/integration_tests/llms/test_azureml_endpoint.py @@ -59,8 +59,8 @@ def test_custom_formatter() -> None: """Test ability to create a custom content formatter.""" class CustomFormatter(ContentFormatterBase): - content_type = "application/json" - accepts = "application/json" + content_type: str = "application/json" + accepts: str = "application/json" def format_request_payload(self, prompt: str, model_kwargs: Dict) -> bytes: # type: ignore[override] input_str = json.dumps( @@ -101,8 +101,8 @@ def test_invalid_request_format() -> None: """Test invalid request format.""" class CustomContentFormatter(ContentFormatterBase): - content_type = "application/json" - accepts = "application/json" + content_type: str = "application/json" + accepts: str = "application/json" def format_request_payload(self, prompt: str, model_kwargs: Dict) -> bytes: # type: ignore[override] input_str = json.dumps( diff --git a/libs/community/tests/integration_tests/tools/nuclia/test_nuclia.py b/libs/community/tests/integration_tests/tools/nuclia/test_nuclia.py index 4847673068b..9577102eb51 100644 --- a/libs/community/tests/integration_tests/tools/nuclia/test_nuclia.py +++ b/libs/community/tests/integration_tests/tools/nuclia/test_nuclia.py @@ -13,19 +13,19 @@ README_PATH = Path(__file__).parents[4] / "README.md" class FakeUploadResponse: - status_code = 200 - text = "fake_uuid" + status_code: int = 200 + text: str = "fake_uuid" class FakePushResponse: - status_code = 200 + status_code: int = 200 def json(self) -> Any: return {"uuid": "fake_uuid"} class FakePullResponse: - status_code = 200 + status_code: int = 200 def json(self) -> Any: return { diff --git a/libs/community/tests/unit_tests/chat_models/test_kinetica.py b/libs/community/tests/unit_tests/chat_models/test_kinetica.py index aec25b17dfb..87824c775a6 100644 --- a/libs/community/tests/unit_tests/chat_models/test_kinetica.py +++ b/libs/community/tests/unit_tests/chat_models/test_kinetica.py @@ -11,7 +11,7 @@ LOG = logging.getLogger(__name__) class TestChatKinetica: - test_ctx_json = """ + test_ctx_json: str = """ { "payload":{ "context":[ diff --git a/libs/community/tests/unit_tests/document_loaders/test_confluence.py b/libs/community/tests/unit_tests/document_loaders/test_confluence.py index e6819a48a88..feecb1588b5 100644 --- a/libs/community/tests/unit_tests/document_loaders/test_confluence.py +++ b/libs/community/tests/unit_tests/document_loaders/test_confluence.py @@ -20,10 +20,10 @@ def mock_confluence(): # type: ignore @pytest.mark.requires("atlassian", "bs4", "lxml") class TestConfluenceLoader: - CONFLUENCE_URL = "https://example.atlassian.com/wiki" - MOCK_USERNAME = "user@gmail.com" - MOCK_API_TOKEN = "api_token" - MOCK_SPACE_KEY = "spaceId123" + CONFLUENCE_URL: str = "https://example.atlassian.com/wiki" + MOCK_USERNAME: str = "user@gmail.com" + MOCK_API_TOKEN: str = "api_token" + MOCK_SPACE_KEY: str = "spaceId123" def test_confluence_loader_initialization(self, mock_confluence: MagicMock) -> None: ConfluenceLoader( diff --git a/libs/community/tests/unit_tests/document_loaders/test_lakefs.py b/libs/community/tests/unit_tests/document_loaders/test_lakefs.py index 706f987e085..37e5058a8f2 100644 --- a/libs/community/tests/unit_tests/document_loaders/test_lakefs.py +++ b/libs/community/tests/unit_tests/document_loaders/test_lakefs.py @@ -57,12 +57,12 @@ def mock_lakefs_client_no_presign_local() -> Any: class TestLakeFSLoader(unittest.TestCase): - lakefs_access_key = "lakefs_access_key" - lakefs_secret_key = "lakefs_secret_key" - endpoint = "endpoint" - repo = "repo" - ref = "ref" - path = "path" + lakefs_access_key: str = "lakefs_access_key" + lakefs_secret_key: str = "lakefs_secret_key" + endpoint: str = "endpoint" + repo: str = "repo" + ref: str = "ref" + path: str = "path" @requests_mock.Mocker() @pytest.mark.usefixtures("mock_lakefs_client_no_presign_not_local") diff --git a/libs/community/tests/unit_tests/document_loaders/test_psychic.py b/libs/community/tests/unit_tests/document_loaders/test_psychic.py index 8511040d4e4..94020e0dbb5 100644 --- a/libs/community/tests/unit_tests/document_loaders/test_psychic.py +++ b/libs/community/tests/unit_tests/document_loaders/test_psychic.py @@ -21,9 +21,9 @@ def mock_connector_id(): # type: ignore @pytest.mark.requires("psychicapi") class TestPsychicLoader: - MOCK_API_KEY = "api_key" - MOCK_CONNECTOR_ID = "notion" - MOCK_ACCOUNT_ID = "account_id" + MOCK_API_KEY: str = "api_key" + MOCK_CONNECTOR_ID: str = "notion" + MOCK_ACCOUNT_ID: str = "account_id" def test_psychic_loader_initialization( self, mock_psychic: MagicMock, mock_connector_id: MagicMock diff --git a/libs/community/tests/unit_tests/document_loaders/test_rspace_loader.py b/libs/community/tests/unit_tests/document_loaders/test_rspace_loader.py index 47fd3ac566a..d70ba867554 100644 --- a/libs/community/tests/unit_tests/document_loaders/test_rspace_loader.py +++ b/libs/community/tests/unit_tests/document_loaders/test_rspace_loader.py @@ -4,9 +4,9 @@ from langchain_community.document_loaders.rspace import RSpaceLoader class TestRSpaceLoader(unittest.TestCase): - url = "https://community.researchspace.com" - api_key = "myapikey" - global_id = "SD12345" + url: str = "https://community.researchspace.com" + api_key: str = "myapikey" + global_id: str = "SD12345" def test_valid_arguments(self) -> None: loader = RSpaceLoader( diff --git a/libs/community/tests/unit_tests/embeddings/test_gradient_ai.py b/libs/community/tests/unit_tests/embeddings/test_gradient_ai.py index 1bec4a7bf63..583e11389cd 100644 --- a/libs/community/tests/unit_tests/embeddings/test_gradient_ai.py +++ b/libs/community/tests/unit_tests/embeddings/test_gradient_ai.py @@ -70,7 +70,7 @@ class MockGradientaiPackage(MagicMock): """Mock Gradientai package.""" Gradient = MockGradient - __version__ = "1.4.0" + __version__: str = "1.4.0" def test_gradient_llm_sync() -> None: diff --git a/libs/community/tests/unit_tests/embeddings/test_ollama.py b/libs/community/tests/unit_tests/embeddings/test_ollama.py index aea354eca8c..0a74216ffb0 100644 --- a/libs/community/tests/unit_tests/embeddings/test_ollama.py +++ b/libs/community/tests/unit_tests/embeddings/test_ollama.py @@ -5,7 +5,7 @@ from langchain_community.embeddings.ollama import OllamaEmbeddings class MockResponse: - status_code = 200 + status_code: int = 200 def json(self) -> dict: return {"embedding": [1, 2, 3]}