Skip to content

Commit

Permalink
Fixing lint
Browse files Browse the repository at this point in the history
  • Loading branch information
hdahme committed Jan 20, 2025
1 parent 73df0a8 commit ad2688c
Show file tree
Hide file tree
Showing 15 changed files with 76 additions and 73 deletions.
6 changes: 3 additions & 3 deletions libs/community/langchain_community/callbacks/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions libs/community/langchain_community/chat_models/bedrock.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down
12 changes: 6 additions & 6 deletions libs/community/langchain_community/llms/databricks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
24 changes: 12 additions & 12 deletions libs/community/langchain_community/tools/databricks/_execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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 = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
12 changes: 6 additions & 6 deletions libs/community/langchain_community/utilities/portkey.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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

Expand Down
3 changes: 2 additions & 1 deletion libs/community/langchain_community/utilities/sql_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 6 additions & 6 deletions libs/community/langchain_community/vectorstores/clarifai.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions libs/community/langchain_community/vectorstores/infinispanvs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
24 changes: 12 additions & 12 deletions libs/community/langchain_community/vectorstores/milvus.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions libs/community/langchain_community/vectorstores/myscale.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
8 changes: 4 additions & 4 deletions libs/community/langchain_community/vectorstores/rocksetdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions libs/community/langchain_community/vectorstores/surrealdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ad2688c

Please sign in to comment.