ref: Apply ruff rules preview autofix (#4699)

Apply ruff rules preview autofix
This commit is contained in:
Christophe Bornet 2024-11-26 00:42:38 +01:00 • committed by GitHub
commit 598e6bc5ae
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
25 changed files with 50 additions and 50 deletions

View file

@ -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} 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( async def share_component(
component: StoreComponentCreate, component: StoreComponentCreate,
store_api_key: Annotated[str, Depends(get_user_store_api_key)], store_api_key: Annotated[str, Depends(get_user_store_api_key)],
@ -123,7 +123,7 @@ async def get_components(
raise HTTPException(status_code=500, detail=str(exc)) from exc 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( async def download_component(
component_id: UUID, component_id: UUID,
store_api_key: Annotated[str, Depends(get_user_store_api_key)], store_api_key: Annotated[str, Depends(get_user_store_api_key)],

View file

@ -9,11 +9,11 @@ from .update_page_property import NotionPageUpdate
__all__ = [ __all__ = [
"AddContentToPage", "AddContentToPage",
"NotionPageCreator",
"NotionDatabaseProperties", "NotionDatabaseProperties",
"NotionListPages", "NotionListPages",
"NotionUserList",
"NotionPageContent", "NotionPageContent",
"NotionSearch", "NotionPageCreator",
"NotionPageUpdate", "NotionPageUpdate",
"NotionSearch",
"NotionUserList",
] ]

View file

@ -8,6 +8,6 @@ __all__ = [
"AssemblyAIGetSubtitles", "AssemblyAIGetSubtitles",
"AssemblyAILeMUR", "AssemblyAILeMUR",
"AssemblyAIListTranscripts", "AssemblyAIListTranscripts",
"AssemblyAITranscriptionJobPoller",
"AssemblyAITranscriptionJobCreator", "AssemblyAITranscriptionJobCreator",
"AssemblyAITranscriptionJobPoller",
] ]

View file

@ -10,6 +10,6 @@ __all__ = [
"HierarchicalCrewComponent", "HierarchicalCrewComponent",
"HierarchicalTaskComponent", "HierarchicalTaskComponent",
"SequentialCrewComponent", "SequentialCrewComponent",
"SequentialTaskComponent",
"SequentialTaskAgentComponent", "SequentialTaskAgentComponent",
"SequentialTaskComponent",
] ]

View file

@ -12,8 +12,8 @@ __all__ = [
"CSVToDataComponent", "CSVToDataComponent",
"DirectoryComponent", "DirectoryComponent",
"FileComponent", "FileComponent",
"JSONToDataComponent",
"SQLExecutorComponent", "SQLExecutorComponent",
"URLComponent", "URLComponent",
"WebhookComponent", "WebhookComponent",
"JSONToDataComponent",
] ]

View file

@ -20,6 +20,7 @@ __all__ = [
"AstraVectorizeComponent", "AstraVectorizeComponent",
"AzureOpenAIEmbeddingsComponent", "AzureOpenAIEmbeddingsComponent",
"CohereEmbeddingsComponent", "CohereEmbeddingsComponent",
"EmbeddingSimilarityComponent",
"GoogleGenerativeAIEmbeddingsComponent", "GoogleGenerativeAIEmbeddingsComponent",
"HuggingFaceInferenceAPIEmbeddingsComponent", "HuggingFaceInferenceAPIEmbeddingsComponent",
"LMStudioEmbeddingsComponent", "LMStudioEmbeddingsComponent",
@ -27,7 +28,6 @@ __all__ = [
"NVIDIAEmbeddingsComponent", "NVIDIAEmbeddingsComponent",
"OllamaEmbeddingsComponent", "OllamaEmbeddingsComponent",
"OpenAIEmbeddingsComponent", "OpenAIEmbeddingsComponent",
"EmbeddingSimilarityComponent",
"TextEmbedderComponent", "TextEmbedderComponent",
"VertexAIEmbeddingsComponent", "VertexAIEmbeddingsComponent",
] ]

View file

@ -10,8 +10,8 @@ __all__ = [
"CreateListComponent", "CreateListComponent",
"CurrentDateComponent", "CurrentDateComponent",
"IDGeneratorComponent", "IDGeneratorComponent",
"OutputParserComponent",
"StructuredOutputComponent",
"StoreMessageComponent",
"MemoryComponent", "MemoryComponent",
"OutputParserComponent",
"StoreMessageComponent",
"StructuredOutputComponent",
] ]

View file

@ -28,32 +28,32 @@ from .vector_store_router import VectorStoreRouterAgentComponent
from .xml import XMLAgentComponent from .xml import XMLAgentComponent
__all__ = [ __all__ = [
"CSVAgentComponent",
"CharacterTextSplitterComponent", "CharacterTextSplitterComponent",
"ConversationChainComponent", "ConversationChainComponent",
"CSVAgentComponent",
"FakeEmbeddingsComponent", "FakeEmbeddingsComponent",
"HtmlLinkExtractorComponent", "HtmlLinkExtractorComponent",
"JSONDocumentBuilder", "JSONDocumentBuilder",
"JsonAgentComponent", "JsonAgentComponent",
"LangChainHubPromptComponent",
"LanguageRecursiveTextSplitterComponent",
"LLMCheckerChainComponent", "LLMCheckerChainComponent",
"LLMMathChainComponent", "LLMMathChainComponent",
"LangChainHubPromptComponent",
"LanguageRecursiveTextSplitterComponent",
"NaturalLanguageTextSplitterComponent", "NaturalLanguageTextSplitterComponent",
"OpenAIToolsAgentComponent", "OpenAIToolsAgentComponent",
"OpenAPIAgentComponent", "OpenAPIAgentComponent",
"RecursiveCharacterTextSplitterComponent", "RecursiveCharacterTextSplitterComponent",
"RetrievalQAComponent", "RetrievalQAComponent",
"RunnableExecComponent", "RunnableExecComponent",
"SelfQueryRetrieverComponent",
"SpiderTool",
"SQLAgentComponent", "SQLAgentComponent",
"SQLDatabaseComponent", "SQLDatabaseComponent",
"SQLGeneratorComponent", "SQLGeneratorComponent",
"SelfQueryRetrieverComponent",
"SemanticTextSplitterComponent",
"SpiderTool",
"ToolCallingAgentComponent", "ToolCallingAgentComponent",
"VectoStoreRetrieverComponent", "VectoStoreRetrieverComponent",
"VectorStoreInfoComponent", "VectorStoreInfoComponent",
"VectorStoreRouterAgentComponent", "VectorStoreRouterAgentComponent",
"XMLAgentComponent", "XMLAgentComponent",
"SemanticTextSplitterComponent",
] ]

View file

@ -34,7 +34,7 @@ class JsonAgentComponent(LCAgentComponent):
def build_agent(self) -> AgentExecutor: def build_agent(self) -> AgentExecutor:
path = Path(self.path) path = Path(self.path)
if path.suffix in ("yaml", "yml"): if path.suffix in {"yaml", "yml"}:
with path.open(encoding="utf-8") as file: with path.open(encoding="utf-8") as file:
yaml_dict = yaml.safe_load(file) yaml_dict = yaml.safe_load(file)
spec = JsonSpec(dict_=yaml_dict) spec = JsonSpec(dict_=yaml_dict)

View file

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

View file

@ -8,12 +8,12 @@ from .run_flow import RunFlowComponent
from .sub_flow import SubFlowComponent from .sub_flow import SubFlowComponent
__all__ = [ __all__ = [
"ConditionalRouterComponent",
"DataConditionalRouterComponent", "DataConditionalRouterComponent",
"FlowToolComponent", "FlowToolComponent",
"ListenComponent", "ListenComponent",
"NotifyComponent", "NotifyComponent",
"PassMessageComponent",
"RunFlowComponent", "RunFlowComponent",
"SubFlowComponent", "SubFlowComponent",
"ConditionalRouterComponent",
"PassMessageComponent",
] ]

View file

@ -7,7 +7,7 @@ from .zep import ZepChatMemory
__all__ = [ __all__ = [
"AstraDBChatMemory", "AstraDBChatMemory",
"CassandraChatMemory", "CassandraChatMemory",
"Mem0MemoryComponent",
"RedisIndexChatMemory", "RedisIndexChatMemory",
"ZepChatMemory", "ZepChatMemory",
"Mem0MemoryComponent",
] ]

View file

@ -103,13 +103,13 @@ class Mem0MemoryComponent(LCChatMemoryComponent):
def ingest_data(self) -> Memory: def ingest_data(self) -> Memory:
"""Ingests a new message into Mem0 memory and returns the updated memory instance.""" """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: if not self.ingest_message or not self.user_id:
logger.warning("Missing 'ingest_message' or 'user_id'; cannot ingest data.") logger.warning("Missing 'ingest_message' or 'user_id'; cannot ingest data.")
return mem0_memory 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) logger.info("Ingesting message for user_id: %s", self.user_id)

View file

@ -60,7 +60,7 @@ class AIMLModelComponent(LCModelComponent):
@override @override
def update_build_config(self, build_config: dict, field_value: str, field_name: str | None = None): 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 = AimlModels()
aiml.get_aiml_models() aiml.get_aiml_models()
build_config["model_name"]["options"] = aiml.chat_models build_config["model_name"]["options"] = aiml.chat_models

View file

@ -12,16 +12,16 @@ from .split_text import SplitTextComponent
from .update_data import UpdateDataComponent from .update_data import UpdateDataComponent
__all__ = [ __all__ = [
"CombineTextComponent",
"CreateDataComponent", "CreateDataComponent",
"ExtractDataKeyComponent",
"DataFilterComponent", "DataFilterComponent",
"ExtractDataKeyComponent",
"JSONCleaner",
"MergeDataComponent", "MergeDataComponent",
"MessageToDataComponent", "MessageToDataComponent",
"ParseDataComponent", "ParseDataComponent",
"SelectDataComponent",
"UpdateDataComponent",
"ParseJSONDataComponent", "ParseJSONDataComponent",
"JSONCleaner", "SelectDataComponent",
"CombineTextComponent",
"SplitTextComponent", "SplitTextComponent",
"UpdateDataComponent",
] ]

View file

@ -33,15 +33,15 @@ __all__ = [
"BingSearchAPIComponent", "BingSearchAPIComponent",
"CalculatorToolComponent", "CalculatorToolComponent",
"DuckDuckGoSearchComponent", "DuckDuckGoSearchComponent",
"ExaSearchToolkit",
"GleanSearchAPIComponent", "GleanSearchAPIComponent",
"GoogleSearchAPIComponent", "GoogleSearchAPIComponent",
"GoogleSerperAPIComponent", "GoogleSerperAPIComponent",
"ExaSearchToolkit",
"PythonCodeStructuredTool", "PythonCodeStructuredTool",
"PythonREPLToolComponent", "PythonREPLToolComponent",
"RetrieverToolComponent", "RetrieverToolComponent",
"SearchAPIComponent",
"SearXNGToolComponent", "SearXNGToolComponent",
"SearchAPIComponent",
"SerpAPIComponent", "SerpAPIComponent",
"TavilySearchToolComponent", "TavilySearchToolComponent",
"WikidataAPIComponent", "WikidataAPIComponent",

View file

@ -95,7 +95,7 @@ class YouTubeTranscriptsComponent(LCToolComponent):
else TranscriptFormat.CHUNKS, else TranscriptFormat.CHUNKS,
chunk_size_seconds=self.chunk_size_seconds, chunk_size_seconds=self.chunk_size_seconds,
language=self.language.split(",") if self.language else ["en"], 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() transcripts = loader.load()
@ -140,7 +140,7 @@ class YouTubeTranscriptsComponent(LCToolComponent):
else TranscriptFormat.CHUNKS, else TranscriptFormat.CHUNKS,
chunk_size_seconds=chunk_size_seconds, chunk_size_seconds=chunk_size_seconds,
language=language.split(",") if language else ["en"], language=language.split(",") if language else ["en"],
translation=translation if translation else None, translation=translation or None,
) )
transcripts = loader.load() transcripts = loader.load()

View file

@ -42,8 +42,8 @@ __all__ = [
"RedisVectorStoreComponent", "RedisVectorStoreComponent",
"SupabaseVectorStoreComponent", "SupabaseVectorStoreComponent",
"UpstashVectorStoreComponent", "UpstashVectorStoreComponent",
"VectaraVectorStoreComponent",
"VectaraRagComponent", "VectaraRagComponent",
"VectaraSelfQueryRetriverComponent", "VectaraSelfQueryRetriverComponent",
"VectaraVectorStoreComponent",
"WeaviateVectorStoreComponent", "WeaviateVectorStoreComponent",
] ]

View file

@ -62,7 +62,7 @@ class EventManager:
def send_event(self, *, event_type: Literal["message", "error", "warning", "info", "token"], data: LoggableType): def send_event(self, *, event_type: Literal["message", "error", "warning", "info", "token"], data: LoggableType):
try: 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) data = create_event_by_type(event_type, **data)
except TypeError as e: except TypeError as e:
logger.debug(f"Error creating playground event: {e}") logger.debug(f"Error creating playground event: {e}")

View file

@ -195,13 +195,13 @@ class Edge:
def __hash__(self) -> int: def __hash__(self) -> int:
return hash(self.__repr__()) return hash(self.__repr__())
def __eq__(self, __o: object) -> bool: def __eq__(self, /, other: object) -> bool:
if not isinstance(__o, Edge): if not isinstance(other, Edge):
return False return False
return ( return (
self._source_handle == __o._source_handle self._source_handle == other._source_handle
and self._target_handle == __o._target_handle and self._target_handle == other._target_handle
and self.target_param == __o.target_param and self.target_param == other.target_param
) )
def __str__(self) -> str: def __str__(self) -> str:

View file

@ -1072,7 +1072,7 @@ class Graph:
else: else:
return graph return graph
def __eq__(self, other: object) -> bool: def __eq__(self, /, other: object) -> bool:
if not isinstance(other, Graph): if not isinstance(other, Graph):
return False return False
return self.__repr__() == other.__repr__() return self.__repr__() == other.__repr__()

View file

@ -6,7 +6,7 @@ class Finish:
def __bool__(self) -> bool: def __bool__(self) -> bool:
return True return True
def __eq__(self, other): def __eq__(self, /, other):
return isinstance(other, Finish) return isinstance(other, Finish)

View file

@ -845,16 +845,16 @@ class Vertex:
def __repr__(self) -> str: def __repr__(self) -> str:
return f"Vertex(display_name={self.display_name}, id={self.id}, data={self.data})" 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: try:
if not isinstance(__o, Vertex): if not isinstance(other, Vertex):
return False return False
# We should create a more robust comparison # We should create a more robust comparison
# for the Vertex class # 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 # self.data is a dict and we need to compare them
# to check if they are equal # to check if they are equal
data_are_equal = self.data == __o.data data_are_equal = self.data == other.data
except AttributeError: except AttributeError:
return False return False
else: else:

View file

@ -204,7 +204,7 @@ class Data(BaseModel):
def __contains__(self, key) -> bool: def __contains__(self, key) -> bool:
return key in self.data return key in self.data
def __eq__(self, other): def __eq__(self, /, other):
return isinstance(other, Data) and self.data == other.data return isinstance(other, Data) and self.data == other.data

View file

@ -104,7 +104,7 @@ class Message(Data):
value = [value] value = [value]
return value return value
def model_post_init(self, __context: Any) -> None: def model_post_init(self, /, _context: Any) -> None:
new_files: list[Any] = [] new_files: list[Any] = []
for file in self.files or []: for file in self.files or []:
if is_image_file(file): if is_image_file(file):