Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ref: Apply ruff rules preview autofix #4699

Merged
merged 3 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/backend/base/langflow/api/v1/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ async def check_if_store_has_api_key(
return {"has_api_key": api_key is not None, "is_valid": is_valid}


@router.post("/components/", response_model=CreateComponentResponse, status_code=201)
@router.post("/components/", status_code=201)
async def share_component(
component: StoreComponentCreate,
store_api_key: Annotated[str, Depends(get_user_store_api_key)],
Expand Down Expand Up @@ -123,7 +123,7 @@ async def get_components(
raise HTTPException(status_code=500, detail=str(exc)) from exc


@router.get("/components/{component_id}", response_model=DownloadComponentResponse)
@router.get("/components/{component_id}")
async def download_component(
component_id: UUID,
store_api_key: Annotated[str, Depends(get_user_store_api_key)],
Expand Down
6 changes: 3 additions & 3 deletions src/backend/base/langflow/components/Notion/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@

__all__ = [
"AddContentToPage",
"NotionPageCreator",
"NotionDatabaseProperties",
"NotionListPages",
"NotionUserList",
"NotionPageContent",
"NotionSearch",
"NotionPageCreator",
"NotionPageUpdate",
"NotionSearch",
"NotionUserList",
]
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
"AssemblyAIGetSubtitles",
"AssemblyAILeMUR",
"AssemblyAIListTranscripts",
"AssemblyAITranscriptionJobPoller",
"AssemblyAITranscriptionJobCreator",
"AssemblyAITranscriptionJobPoller",
]
2 changes: 1 addition & 1 deletion src/backend/base/langflow/components/crewai/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
"HierarchicalCrewComponent",
"HierarchicalTaskComponent",
"SequentialCrewComponent",
"SequentialTaskComponent",
"SequentialTaskAgentComponent",
"SequentialTaskComponent",
]
2 changes: 1 addition & 1 deletion src/backend/base/langflow/components/data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
"CSVToDataComponent",
"DirectoryComponent",
"FileComponent",
"JSONToDataComponent",
"SQLExecutorComponent",
"URLComponent",
"WebhookComponent",
"JSONToDataComponent",
]
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
"AstraVectorizeComponent",
"AzureOpenAIEmbeddingsComponent",
"CohereEmbeddingsComponent",
"EmbeddingSimilarityComponent",
"GoogleGenerativeAIEmbeddingsComponent",
"HuggingFaceInferenceAPIEmbeddingsComponent",
"LMStudioEmbeddingsComponent",
"MistralAIEmbeddingsComponent",
"NVIDIAEmbeddingsComponent",
"OllamaEmbeddingsComponent",
"OpenAIEmbeddingsComponent",
"EmbeddingSimilarityComponent",
"TextEmbedderComponent",
"VertexAIEmbeddingsComponent",
]
4 changes: 2 additions & 2 deletions src/backend/base/langflow/components/helpers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"CreateListComponent",
"CurrentDateComponent",
"IDGeneratorComponent",
"MemoryComponent",
"OutputParserComponent",
"StructuredOutputComponent",
"StoreMessageComponent",
"MemoryComponent",
"StructuredOutputComponent",
]
Original file line number Diff line number Diff line change
Expand Up @@ -28,32 +28,32 @@
from .xml import XMLAgentComponent

__all__ = [
"CSVAgentComponent",
"CharacterTextSplitterComponent",
"ConversationChainComponent",
"CSVAgentComponent",
"FakeEmbeddingsComponent",
"HtmlLinkExtractorComponent",
"JSONDocumentBuilder",
"JsonAgentComponent",
"LangChainHubPromptComponent",
"LanguageRecursiveTextSplitterComponent",
"LLMCheckerChainComponent",
"LLMMathChainComponent",
"LangChainHubPromptComponent",
"LanguageRecursiveTextSplitterComponent",
"NaturalLanguageTextSplitterComponent",
"OpenAIToolsAgentComponent",
"OpenAPIAgentComponent",
"RecursiveCharacterTextSplitterComponent",
"RetrievalQAComponent",
"RunnableExecComponent",
"SelfQueryRetrieverComponent",
"SpiderTool",
"SQLAgentComponent",
"SQLDatabaseComponent",
"SQLGeneratorComponent",
"SelfQueryRetrieverComponent",
"SemanticTextSplitterComponent",
"SpiderTool",
"ToolCallingAgentComponent",
"VectoStoreRetrieverComponent",
"VectorStoreInfoComponent",
"VectorStoreRouterAgentComponent",
"XMLAgentComponent",
"SemanticTextSplitterComponent",
]
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class JsonAgentComponent(LCAgentComponent):

def build_agent(self) -> AgentExecutor:
path = Path(self.path)
if path.suffix in ("yaml", "yml"):
if path.suffix in {"yaml", "yml"}:
with path.open(encoding="utf-8") as file:
yaml_dict = yaml.safe_load(file)
spec = JsonSpec(dict_=yaml_dict)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class OpenAPIAgentComponent(LCAgentComponent):

def build_agent(self) -> AgentExecutor:
path = Path(self.path)
if path.suffix in ("yaml", "yml"):
if path.suffix in {"yaml", "yml"}:
with path.open(encoding="utf-8") as file:
yaml_dict = yaml.safe_load(file)
spec = JsonSpec(dict_=yaml_dict)
Expand Down
4 changes: 2 additions & 2 deletions src/backend/base/langflow/components/logic/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
from .sub_flow import SubFlowComponent

__all__ = [
"ConditionalRouterComponent",
"DataConditionalRouterComponent",
"FlowToolComponent",
"ListenComponent",
"NotifyComponent",
"PassMessageComponent",
"RunFlowComponent",
"SubFlowComponent",
"ConditionalRouterComponent",
"PassMessageComponent",
]
2 changes: 1 addition & 1 deletion src/backend/base/langflow/components/memories/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
__all__ = [
"AstraDBChatMemory",
"CassandraChatMemory",
"Mem0MemoryComponent",
"RedisIndexChatMemory",
"ZepChatMemory",
"Mem0MemoryComponent",
]
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,13 @@ def build_mem0(self) -> Memory:

def ingest_data(self) -> Memory:
"""Ingests a new message into Mem0 memory and returns the updated memory instance."""
mem0_memory = self.existing_memory if self.existing_memory else self.build_mem0()
mem0_memory = self.existing_memory or self.build_mem0()

if not self.ingest_message or not self.user_id:
logger.warning("Missing 'ingest_message' or 'user_id'; cannot ingest data.")
return mem0_memory

metadata = self.metadata if self.metadata else {}
metadata = self.metadata or {}

logger.info("Ingesting message for user_id: %s", self.user_id)

Expand Down
2 changes: 1 addition & 1 deletion src/backend/base/langflow/components/models/aiml.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class AIMLModelComponent(LCModelComponent):

@override
def update_build_config(self, build_config: dict, field_value: str, field_name: str | None = None):
if field_name in ("api_key", "aiml_api_base", "model_name"):
if field_name in {"api_key", "aiml_api_base", "model_name"}:
aiml = AimlModels()
aiml.get_aiml_models()
build_config["model_name"]["options"] = aiml.chat_models
Expand Down
10 changes: 5 additions & 5 deletions src/backend/base/langflow/components/processing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@
from .update_data import UpdateDataComponent

__all__ = [
"CombineTextComponent",
"CreateDataComponent",
"ExtractDataKeyComponent",
"DataFilterComponent",
"ExtractDataKeyComponent",
"JSONCleaner",
"MergeDataComponent",
"MessageToDataComponent",
"ParseDataComponent",
"SelectDataComponent",
"UpdateDataComponent",
"ParseJSONDataComponent",
"JSONCleaner",
"CombineTextComponent",
"SelectDataComponent",
"SplitTextComponent",
"UpdateDataComponent",
]
4 changes: 2 additions & 2 deletions src/backend/base/langflow/components/tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@
"BingSearchAPIComponent",
"CalculatorToolComponent",
"DuckDuckGoSearchComponent",
"ExaSearchToolkit",
"GleanSearchAPIComponent",
"GoogleSearchAPIComponent",
"GoogleSerperAPIComponent",
"ExaSearchToolkit",
"PythonCodeStructuredTool",
"PythonREPLToolComponent",
"RetrieverToolComponent",
"SearchAPIComponent",
"SearXNGToolComponent",
"SearchAPIComponent",
"SerpAPIComponent",
"TavilySearchToolComponent",
"WikidataAPIComponent",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def build_youtube_transcripts(self) -> Data | list[Data]:
else TranscriptFormat.CHUNKS,
chunk_size_seconds=self.chunk_size_seconds,
language=self.language.split(",") if self.language else ["en"],
translation=self.translation if self.translation else None,
translation=self.translation or None,
)

transcripts = loader.load()
Expand Down Expand Up @@ -140,7 +140,7 @@ def youtube_transcripts(
else TranscriptFormat.CHUNKS,
chunk_size_seconds=chunk_size_seconds,
language=language.split(",") if language else ["en"],
translation=translation if translation else None,
translation=translation or None,
)

transcripts = loader.load()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
"RedisVectorStoreComponent",
"SupabaseVectorStoreComponent",
"UpstashVectorStoreComponent",
"VectaraVectorStoreComponent",
"VectaraRagComponent",
"VectaraSelfQueryRetriverComponent",
"VectaraVectorStoreComponent",
"WeaviateVectorStoreComponent",
]
2 changes: 1 addition & 1 deletion src/backend/base/langflow/events/event_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def register_event(

def send_event(self, *, event_type: Literal["message", "error", "warning", "info", "token"], data: LoggableType):
try:
if isinstance(data, dict) and event_type in ["message", "error", "warning", "info", "token"]:
if isinstance(data, dict) and event_type in {"message", "error", "warning", "info", "token"}:
data = create_event_by_type(event_type, **data)
except TypeError as e:
logger.debug(f"Error creating playground event: {e}")
Expand Down
10 changes: 5 additions & 5 deletions src/backend/base/langflow/graph/edge/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,13 @@ def __repr__(self) -> str:
def __hash__(self) -> int:
return hash(self.__repr__())

def __eq__(self, __o: object) -> bool:
if not isinstance(__o, Edge):
def __eq__(self, /, other: object) -> bool:
if not isinstance(other, Edge):
return False
return (
self._source_handle == __o._source_handle
and self._target_handle == __o._target_handle
and self.target_param == __o.target_param
self._source_handle == other._source_handle
and self._target_handle == other._target_handle
and self.target_param == other.target_param
)

def __str__(self) -> str:
Expand Down
2 changes: 1 addition & 1 deletion src/backend/base/langflow/graph/graph/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1072,7 +1072,7 @@ def from_payload(
else:
return graph

def __eq__(self, other: object) -> bool:
def __eq__(self, /, other: object) -> bool:
if not isinstance(other, Graph):
return False
return self.__repr__() == other.__repr__()
Expand Down
2 changes: 1 addition & 1 deletion src/backend/base/langflow/graph/graph/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Finish:
def __bool__(self) -> bool:
return True

def __eq__(self, other):
def __eq__(self, /, other):
return isinstance(other, Finish)


Expand Down
8 changes: 4 additions & 4 deletions src/backend/base/langflow/graph/vertex/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -845,16 +845,16 @@ def add_edge(self, edge: CycleEdge) -> None:
def __repr__(self) -> str:
return f"Vertex(display_name={self.display_name}, id={self.id}, data={self.data})"

def __eq__(self, __o: object) -> bool:
def __eq__(self, /, other: object) -> bool:
try:
if not isinstance(__o, Vertex):
if not isinstance(other, Vertex):
return False
# We should create a more robust comparison
# for the Vertex class
ids_are_equal = self.id == __o.id
ids_are_equal = self.id == other.id
# self.data is a dict and we need to compare them
# to check if they are equal
data_are_equal = self.data == __o.data
data_are_equal = self.data == other.data
except AttributeError:
return False
else:
Expand Down
2 changes: 1 addition & 1 deletion src/backend/base/langflow/schema/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def __str__(self) -> str:
def __contains__(self, key) -> bool:
return key in self.data

def __eq__(self, other):
def __eq__(self, /, other):
return isinstance(other, Data) and self.data == other.data


Expand Down
2 changes: 1 addition & 1 deletion src/backend/base/langflow/schema/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def validate_files(cls, value):
value = [value]
return value

def model_post_init(self, __context: Any) -> None:
def model_post_init(self, /, _context: Any) -> None:
new_files: list[Any] = []
for file in self.files or []:
if is_image_file(file):
Expand Down