From ad2688c167afd1df99b205bdc1af255ffb2d2749 Mon Sep 17 00:00:00 2001 From: hdahme Date: Sun, 19 Jan 2025 15:45:48 -0800 Subject: [PATCH] Fixing lint --- .../langchain_community/callbacks/manager.py | 6 ++--- .../streamlit/streamlit_callback_handler.py | 6 ++--- .../chat_message_histories/sql.py | 6 ++--- .../chat_models/bedrock.py | 6 ++--- .../langchain_community/llms/databricks.py | 12 +++++----- .../tools/databricks/_execution.py | 24 +++++++++---------- .../tools/office365/send_event.py | 6 +++-- .../langchain_community/utilities/portkey.py | 12 +++++----- .../utilities/sql_database.py | 3 ++- .../vectorstores/clarifai.py | 12 +++++----- .../vectorstores/infinispanvs.py | 12 +++++----- .../vectorstores/milvus.py | 24 +++++++++---------- .../vectorstores/myscale.py | 6 ++--- .../vectorstores/rocksetdb.py | 8 +++---- .../vectorstores/surrealdb.py | 6 ++--- 15 files changed, 76 insertions(+), 73 deletions(-) diff --git a/libs/community/langchain_community/callbacks/manager.py b/libs/community/langchain_community/callbacks/manager.py index 8e8d052560602..ba942084953f6 100644 --- a/libs/community/langchain_community/callbacks/manager.py +++ b/libs/community/langchain_community/callbacks/manager.py @@ -61,9 +61,9 @@ def get_openai_callback() -> Generator[OpenAICallbackHandler, None, None]: @contextmanager -def get_bedrock_anthropic_callback() -> Generator[ - BedrockAnthropicTokenUsageCallbackHandler, None, None -]: +def get_bedrock_anthropic_callback() -> ( + Generator[BedrockAnthropicTokenUsageCallbackHandler, None, None] +): """Get the Bedrock anthropic callback handler in a context manager. which conveniently exposes token and cost information. diff --git a/libs/community/langchain_community/callbacks/streamlit/streamlit_callback_handler.py b/libs/community/langchain_community/callbacks/streamlit/streamlit_callback_handler.py index 4747bfc2f690d..5d5985c039cb7 100644 --- a/libs/community/langchain_community/callbacks/streamlit/streamlit_callback_handler.py +++ b/libs/community/langchain_community/callbacks/streamlit/streamlit_callback_handler.py @@ -211,9 +211,9 @@ def on_agent_action( def complete(self, final_label: Optional[str] = None) -> None: """Finish the thought.""" if final_label is None and self._state == LLMThoughtState.RUNNING_TOOL: - assert self._last_tool is not None, ( - "_last_tool should never be null when _state == RUNNING_TOOL" - ) + assert ( + self._last_tool is not None + ), "_last_tool should never be null when _state == RUNNING_TOOL" final_label = self._labeler.get_tool_label( self._last_tool, is_complete=True ) diff --git a/libs/community/langchain_community/chat_message_histories/sql.py b/libs/community/langchain_community/chat_message_histories/sql.py index 8c0706b7ee0d9..2c3b2351c471d 100644 --- a/libs/community/langchain_community/chat_message_histories/sql.py +++ b/libs/community/langchain_community/chat_message_histories/sql.py @@ -177,9 +177,9 @@ def __init__( engine_args: Additional configuration for creating database engines. async_mode: Whether it is an asynchronous connection. """ - assert not (connection_string and connection), ( - "connection_string and connection are mutually exclusive" - ) + assert not ( + connection_string and connection + ), "connection_string and connection are mutually exclusive" if connection_string: global _warned_once_already if not _warned_once_already: diff --git a/libs/community/langchain_community/chat_models/bedrock.py b/libs/community/langchain_community/chat_models/bedrock.py index 086a4d461301f..6b36208390379 100644 --- a/libs/community/langchain_community/chat_models/bedrock.py +++ b/libs/community/langchain_community/chat_models/bedrock.py @@ -110,9 +110,9 @@ def _format_anthropic_messages( if not isinstance(message.content, str): # parse as dict - assert isinstance(message.content, list), ( - "Anthropic message content must be str or list of dicts" - ) + assert isinstance( + message.content, list + ), "Anthropic message content must be str or list of dicts" # populate content content = [] diff --git a/libs/community/langchain_community/llms/databricks.py b/libs/community/langchain_community/llms/databricks.py index 4b656192e2b51..3f7aa42f2fda6 100644 --- a/libs/community/langchain_community/llms/databricks.py +++ b/libs/community/langchain_community/llms/databricks.py @@ -457,12 +457,12 @@ def set_cluster_id(cls, values: Dict[str, Any]) -> dict: pass if model_kwargs := values.get("model_kwargs"): - assert "prompt" not in model_kwargs, ( - "model_kwargs must not contain key 'prompt'" - ) - assert "stop" not in model_kwargs, ( - "model_kwargs must not contain key 'stop'" - ) + assert ( + "prompt" not in model_kwargs + ), "model_kwargs must not contain key 'prompt'" + assert ( + "stop" not in model_kwargs + ), "model_kwargs must not contain key 'stop'" return values def __init__(self, **data: Any): diff --git a/libs/community/langchain_community/tools/databricks/_execution.py b/libs/community/langchain_community/tools/databricks/_execution.py index 09693e5510754..62e8414fe49a3 100644 --- a/libs/community/langchain_community/tools/databricks/_execution.py +++ b/libs/community/langchain_community/tools/databricks/_execution.py @@ -66,9 +66,9 @@ def get_execute_function_sql_stmt( else: parts.append(f"SELECT * FROM {function.full_name}(") if function.input_params is None or function.input_params.parameters is None: - assert not json_params, ( - "Function has no parameters but parameters were provided." - ) + assert ( + not json_params + ), "Function has no parameters but parameters were provided." else: args = [] use_named_args = False @@ -213,17 +213,17 @@ def execute_function( assert response.status is not None, f"Statement execution failed: {response}" if response.status.state != StatementState.SUCCEEDED: error = response.status.error - assert error is not None, ( - f"Statement execution failed but no error message was provided: {response}" - ) + assert ( + error is not None + ), f"Statement execution failed but no error message was provided: {response}" return FunctionExecutionResult(error=f"{error.error_code}: {error.message}") manifest = response.manifest assert manifest is not None truncated = manifest.truncated result = response.result - assert result is not None, ( - "Statement execution succeeded but no result was provided." - ) + assert ( + result is not None + ), "Statement execution succeeded but no result was provided." data_array = result.data_array if is_scalar(function): value = None @@ -234,9 +234,9 @@ def execute_function( ) else: schema = manifest.schema - assert schema is not None and schema.columns is not None, ( - "Statement execution succeeded but no schema was provided." - ) + assert ( + schema is not None and schema.columns is not None + ), "Statement execution succeeded but no schema was provided." columns = [c.name for c in schema.columns] if data_array is None: data_array = [] diff --git a/libs/community/langchain_community/tools/office365/send_event.py b/libs/community/langchain_community/tools/office365/send_event.py index a943ec01b3933..e7513025ac1f4 100644 --- a/libs/community/langchain_community/tools/office365/send_event.py +++ b/libs/community/langchain_community/tools/office365/send_event.py @@ -6,12 +6,14 @@ from datetime import datetime as dt from typing import List, Optional, Type + +from langchain_core.callbacks import CallbackManagerForToolRun +from pydantic import BaseModel, Field from zoneinfo import ZoneInfo from langchain_community.tools.office365.base import O365BaseTool from langchain_community.tools.office365.utils import UTC_FORMAT -from langchain_core.callbacks import CallbackManagerForToolRun -from pydantic import BaseModel, Field + class SendEventSchema(BaseModel): """Input for CreateEvent Tool.""" diff --git a/libs/community/langchain_community/utilities/portkey.py b/libs/community/langchain_community/utilities/portkey.py index 5eb16f7af518b..dbaf41840f072 100644 --- a/libs/community/langchain_community/utilities/portkey.py +++ b/libs/community/langchain_community/utilities/portkey.py @@ -26,9 +26,9 @@ def Config( cache_force_refresh: Optional[str] = None, cache_age: Optional[int] = None, ) -> Dict[str, str]: - assert retry_count is None or retry_count in range(1, 6), ( - "retry_count must be an integer and in range [1, 2, 3, 4, 5]" - ) + assert retry_count is None or retry_count in range( + 1, 6 + ), "retry_count must be an integer and in range [1, 2, 3, 4, 5]" assert cache is None or cache in [ "simple", "semantic", @@ -37,9 +37,9 @@ def Config( isinstance(cache_force_refresh, str) and cache_force_refresh in ["True", "False"] ), "cache_force_refresh must be 'True' or 'False'" - assert cache_age is None or isinstance(cache_age, int), ( - "cache_age must be an integer" - ) + assert cache_age is None or isinstance( + cache_age, int + ), "cache_age must be an integer" os.environ["OPENAI_API_BASE"] = Portkey.base diff --git a/libs/community/langchain_community/utilities/sql_database.py b/libs/community/langchain_community/utilities/sql_database.py index 78dca45e85569..a69dae0dfe9de 100644 --- a/libs/community/langchain_community/utilities/sql_database.py +++ b/libs/community/langchain_community/utilities/sql_database.py @@ -696,7 +696,8 @@ def get_foreign_key_info(self, table_name: str) -> List[Dict[str, Any]]: if table_name not in self._usable_tables: raise ValueError(f"Table '{table_name}' not found in database") - return self._inspector.get_foreign_keys(table_name, schema=self._schema) + fk = self._inspector.get_foreign_keys(table_name, schema=self._schema) + return fk def get_table_info_str(self) -> str: """Get formatted string of table information. diff --git a/libs/community/langchain_community/vectorstores/clarifai.py b/libs/community/langchain_community/vectorstores/clarifai.py index 4cae4bf7cf976..b37b99f02a706 100644 --- a/libs/community/langchain_community/vectorstores/clarifai.py +++ b/libs/community/langchain_community/vectorstores/clarifai.py @@ -115,14 +115,14 @@ def add_texts( assert length > 0, "No texts provided to add to the vectorstore." if metadatas is not None: - assert length == len(metadatas), ( - "Number of texts and metadatas should be the same." - ) + assert length == len( + metadatas + ), "Number of texts and metadatas should be the same." if ids is not None: - assert len(ltexts) == len(ids), ( - "Number of text inputs and input ids should be the same." - ) + assert len(ltexts) == len( + ids + ), "Number of text inputs and input ids should be the same." input_obj = Inputs.from_auth_helper(auth=self._auth) batch_size = 32 diff --git a/libs/community/langchain_community/vectorstores/infinispanvs.py b/libs/community/langchain_community/vectorstores/infinispanvs.py index c9012e17fbef1..9b6e42bf113d3 100644 --- a/libs/community/langchain_community/vectorstores/infinispanvs.py +++ b/libs/community/langchain_community/vectorstores/infinispanvs.py @@ -361,16 +361,16 @@ def _query_result_to_docs( def configure(self, metadata: dict, dimension: int) -> None: schema = self.schema_builder(metadata, dimension) output = self.schema_create(schema) - assert output.status_code == self.ispn.Codes.OK, ( - "Unable to create schema. Already exists? " - ) + assert ( + output.status_code == self.ispn.Codes.OK + ), "Unable to create schema. Already exists? " "Consider using clear_old=True" assert json.loads(output.text)["error"] is None if not self.cache_exists(): output = self.cache_create() - assert output.status_code == self.ispn.Codes.OK, ( - "Unable to create cache. Already exists? " - ) + assert ( + output.status_code == self.ispn.Codes.OK + ), "Unable to create cache. Already exists? " "Consider using clear_old=True" # Ensure index is clean self.cache_index_clear() diff --git a/libs/community/langchain_community/vectorstores/milvus.py b/libs/community/langchain_community/vectorstores/milvus.py index 7dd404999683c..6e207270e5173 100644 --- a/libs/community/langchain_community/vectorstores/milvus.py +++ b/libs/community/langchain_community/vectorstores/milvus.py @@ -550,15 +550,15 @@ def add_texts( texts = list(texts) if not self.auto_id: - assert isinstance(ids, list), ( - "A list of valid ids are required when auto_id is False." - ) - assert len(set(ids)) == len(texts), ( - "Different lengths of texts and unique ids are provided." - ) - assert all(len(x.encode()) <= 65_535 for x in ids), ( - "Each id should be a string less than 65535 bytes." - ) + assert isinstance( + ids, list + ), "A list of valid ids are required when auto_id is False." + assert len(set(ids)) == len( + texts + ), "Different lengths of texts and unique ids are provided." + assert all( + len(x.encode()) <= 65_535 for x in ids + ), "Each id should be a string less than 65535 bytes." try: embeddings = self.embedding_func.embed_documents(texts) @@ -957,9 +957,9 @@ def delete( # type: ignore[no-untyped-def] ) expr = f"{self._primary_field} in {ids}" else: - assert isinstance(expr, str), ( - "Either ids list or expr string must be provided." - ) + assert isinstance( + expr, str + ), "Either ids list or expr string must be provided." return self.col.delete(expr=expr, **kwargs) # type: ignore[union-attr] @classmethod diff --git a/libs/community/langchain_community/vectorstores/myscale.py b/libs/community/langchain_community/vectorstores/myscale.py index 711b525e40606..847a346e1c1f7 100644 --- a/libs/community/langchain_community/vectorstores/myscale.py +++ b/libs/community/langchain_community/vectorstores/myscale.py @@ -475,9 +475,9 @@ def delete( Optional[bool]: True if deletion is successful, False otherwise, None if not implemented. """ - assert not (ids is None and where_str is None), ( - "You need to specify where to be deleted! Either with `ids` or `where_str`" - ) + assert not ( + ids is None and where_str is None + ), "You need to specify where to be deleted! Either with `ids` or `where_str`" conds = [] if ids and len(ids) > 0: id_list = ", ".join([f"'{id}'" for id in ids]) diff --git a/libs/community/langchain_community/vectorstores/rocksetdb.py b/libs/community/langchain_community/vectorstores/rocksetdb.py index 0f5345eda5a8f..263a211fba324 100644 --- a/libs/community/langchain_community/vectorstores/rocksetdb.py +++ b/libs/community/langchain_community/vectorstores/rocksetdb.py @@ -271,10 +271,10 @@ def similarity_search_by_vector_with_relevance_scores( finalResult: list[Tuple[Document, float]] = [] for document in query_response.results: metadata = {} - assert isinstance(document, dict), ( - "document should be of type `dict[str,Any]`. But found: `{}`".format( - type(document) - ) + assert isinstance( + document, dict + ), "document should be of type `dict[str,Any]`. But found: `{}`".format( + type(document) ) for k, v in document.items(): if k == self._text_key: diff --git a/libs/community/langchain_community/vectorstores/surrealdb.py b/libs/community/langchain_community/vectorstores/surrealdb.py index 3157f48e33b27..ce05abdc930ce 100644 --- a/libs/community/langchain_community/vectorstores/surrealdb.py +++ b/libs/community/langchain_community/vectorstores/surrealdb.py @@ -323,9 +323,9 @@ def similarity_search_with_relevance_scores( List of Documents most similar along with relevance scores """ - async def _similarity_search_with_relevance_scores() -> List[ - Tuple[Document, float] - ]: + async def _similarity_search_with_relevance_scores() -> ( + List[Tuple[Document, float]] + ): await self.initialize() return await self.asimilarity_search_with_relevance_scores( query, k, filter=filter, **kwargs