From fa4a01caed91fc54aa170b3dc59f2fa06d1c2856 Mon Sep 17 00:00:00 2001 From: anovazzi1 Date: Thu, 25 Jan 2024 19:11:06 -0300 Subject: [PATCH] chore(RetrievalQAWithSourcesChain.py): reorder imports to improve readability and maintain consistency chore(AZLyricsLoader.py): reorder imports to improve readability and maintain consistency chore(AirbyteJSONLoader.py): reorder imports to improve readability and maintain consistency chore(CoNLLULoader.py): add import for List from typing module to fix type hinting chore(CollegeConfidentialLoader.py): add import for List from typing module to fix type hinting chore(EverNoteLoader.py): reorder imports to improve readability and maintain consistency chore(FacebookChatLoader.py): add import for List from typing module to fix type hinting chore(GitbookLoader.py): reorder imports to improve readability and maintain consistency chore(HNLoader.py): add import for List from typing module to fix type hinting chore(IMSDbLoader.py): add import for List from typing module to fix type hinting chore(TextLoader.py): reorder imports to improve readability and maintain consistency chore(CohereEmbeddings.py): change default value of cohere_api_key parameter to an empty string chore(OpenAIEmbeddings.py): change default values of allowed_special, disallowed_special, chunk_size, embedding_ctx_length, max_retries, show_progress_bar, skip_empty, and tikToken_enable parameters to their respective types --- .../chains/RetrievalQAWithSourcesChain.py | 3 ++- .../components/documentloaders/AZLyricsLoader.py | 4 ++-- .../documentloaders/AirbyteJSONLoader.py | 4 ++-- .../components/documentloaders/CoNLLULoader.py | 3 ++- .../documentloaders/CollegeConfidentialLoader.py | 4 ++-- .../components/documentloaders/EverNoteLoader.py | 4 ++-- .../documentloaders/FacebookChatLoader.py | 6 +++--- .../components/documentloaders/GitbookLoader.py | 4 ++-- .../components/documentloaders/HNLoader.py | 5 +++-- .../components/documentloaders/IMSDbLoader.py | 4 ++-- .../components/documentloaders/TextLoader.py | 2 +- .../components/embeddings/CohereEmbeddings.py | 2 +- .../components/embeddings/OpenAIEmbeddings.py | 14 +++++++------- 13 files changed, 31 insertions(+), 28 deletions(-) diff --git a/src/backend/langflow/components/chains/RetrievalQAWithSourcesChain.py b/src/backend/langflow/components/chains/RetrievalQAWithSourcesChain.py index e10aac6bb..3c46cd8bd 100644 --- a/src/backend/langflow/components/chains/RetrievalQAWithSourcesChain.py +++ b/src/backend/langflow/components/chains/RetrievalQAWithSourcesChain.py @@ -1,6 +1,7 @@ from typing import Optional -from langchain.chains import BaseQAWithSourcesChain, RetrievalQAWithSourcesChain +from langchain.chains import RetrievalQAWithSourcesChain +from langchain.chains.qa_with_sources.base import BaseQAWithSourcesChain from langchain.chains.combine_documents.base import BaseCombineDocumentsChain from langflow import CustomComponent diff --git a/src/backend/langflow/components/documentloaders/AZLyricsLoader.py b/src/backend/langflow/components/documentloaders/AZLyricsLoader.py index eea64c2e1..82d507d68 100644 --- a/src/backend/langflow/components/documentloaders/AZLyricsLoader.py +++ b/src/backend/langflow/components/documentloaders/AZLyricsLoader.py @@ -1,6 +1,6 @@ from langflow import CustomComponent from langflow.field_typing import Document -from typing import Optional, Dict +from typing import List, Optional, Dict from langchain_community.document_loaders.azlyrics import AZLyricsLoader @@ -15,7 +15,7 @@ class AZLyricsLoaderComponent(CustomComponent): "web_path": {"display_name": "Web Page", "type": "str", "required": True, "show": True}, } - def build(self, metadata: Optional[Dict] = None, web_path: str = "") -> Document: + def build(self, metadata: Optional[Dict] = None, web_path: str = "") -> List[Document]: documents = AZLyricsLoader(web_path=web_path).load() if metadata: for document in documents: diff --git a/src/backend/langflow/components/documentloaders/AirbyteJSONLoader.py b/src/backend/langflow/components/documentloaders/AirbyteJSONLoader.py index eaff8fb4a..8c670a8c0 100644 --- a/src/backend/langflow/components/documentloaders/AirbyteJSONLoader.py +++ b/src/backend/langflow/components/documentloaders/AirbyteJSONLoader.py @@ -1,6 +1,6 @@ from langflow import CustomComponent from langflow.field_typing import Document -from typing import Optional, Dict +from typing import List, Optional, Dict from langchain_community.document_loaders.airbyte_json import AirbyteJSONLoader @@ -26,7 +26,7 @@ class AirbyteJSONLoaderComponent(CustomComponent): }, } - def build(self, file_path: str, metadata: Optional[Dict] = None) -> Document: + def build(self, file_path: str, metadata: Optional[Dict] = None) -> List[Document]: documents = AirbyteJSONLoader(file_path=file_path).load() if metadata: for document in documents: diff --git a/src/backend/langflow/components/documentloaders/CoNLLULoader.py b/src/backend/langflow/components/documentloaders/CoNLLULoader.py index 2c243d25d..0cd2de50c 100644 --- a/src/backend/langflow/components/documentloaders/CoNLLULoader.py +++ b/src/backend/langflow/components/documentloaders/CoNLLULoader.py @@ -1,3 +1,4 @@ +from typing import List from langflow import CustomComponent from langchain.docstore.document import Document from langchain_community.document_loaders.conllu import CoNLLULoader @@ -24,7 +25,7 @@ class CoNLLULoaderComponent(CustomComponent): }, } - def build(self, file_path: str, metadata: dict) -> Document: + def build(self, file_path: str, metadata: dict) -> List[Document]: documents = CoNLLULoader(file_path=file_path).load() if metadata: for document in documents: diff --git a/src/backend/langflow/components/documentloaders/CollegeConfidentialLoader.py b/src/backend/langflow/components/documentloaders/CollegeConfidentialLoader.py index dee77c1da..8fea6e5d2 100644 --- a/src/backend/langflow/components/documentloaders/CollegeConfidentialLoader.py +++ b/src/backend/langflow/components/documentloaders/CollegeConfidentialLoader.py @@ -1,6 +1,6 @@ from langflow import CustomComponent from langchain.docstore.document import Document -from typing import Optional +from typing import Optional, List from langchain_community.document_loaders.college_confidential import CollegeConfidentialLoader @@ -17,7 +17,7 @@ class CollegeConfidentialLoaderComponent(CustomComponent): "web_path": {"display_name": "Web Page", "required": True}, } - def build(self, web_path: str, metadata: Optional[dict] = {}) -> Document: + def build(self, web_path: str, metadata: Optional[dict] = {}) -> List[Document]: documents = CollegeConfidentialLoader(web_path=web_path).load() if metadata: for document in documents: diff --git a/src/backend/langflow/components/documentloaders/EverNoteLoader.py b/src/backend/langflow/components/documentloaders/EverNoteLoader.py index ccf925e27..6f7431fcb 100644 --- a/src/backend/langflow/components/documentloaders/EverNoteLoader.py +++ b/src/backend/langflow/components/documentloaders/EverNoteLoader.py @@ -1,6 +1,6 @@ from langflow import CustomComponent from langflow.field_typing import Document -from typing import Optional, Dict +from typing import List, Optional, Dict from langchain_community.document_loaders.evernote import EverNoteLoader @@ -27,7 +27,7 @@ class EverNoteLoaderComponent(CustomComponent): }, } - def build(self, file_path: str, metadata: Optional[Dict] = None) -> Document: + def build(self, file_path: str, metadata: Optional[Dict] = None) -> List[Document]: documents = EverNoteLoader(file_path=file_path).load() if metadata: for document in documents: diff --git a/src/backend/langflow/components/documentloaders/FacebookChatLoader.py b/src/backend/langflow/components/documentloaders/FacebookChatLoader.py index 244066a7e..ecb99eea4 100644 --- a/src/backend/langflow/components/documentloaders/FacebookChatLoader.py +++ b/src/backend/langflow/components/documentloaders/FacebookChatLoader.py @@ -1,6 +1,6 @@ from langflow import CustomComponent from langchain.docstore.document import Document -from typing import Optional, Dict +from typing import List, Optional, Dict from langchain_community.document_loaders.facebook_chat import FacebookChatLoader @@ -26,8 +26,8 @@ class FacebookChatLoaderComponent(CustomComponent): }, } - def build(self, file_path: str, metadata: Optional[Dict] = None) -> Document: - documents = FacebookChatLoader(file_path=file_path).load() + def build(self, file_path: str, metadata: Optional[Dict] = None) -> List[Document]: + documents = FacebookChatLoader(path=file_path).load() if metadata: for document in documents: if not document.metadata: diff --git a/src/backend/langflow/components/documentloaders/GitbookLoader.py b/src/backend/langflow/components/documentloaders/GitbookLoader.py index f53f5959f..05b03e611 100644 --- a/src/backend/langflow/components/documentloaders/GitbookLoader.py +++ b/src/backend/langflow/components/documentloaders/GitbookLoader.py @@ -1,6 +1,6 @@ from langflow import CustomComponent from langflow.field_typing import Document -from typing import Optional, Dict +from typing import List, Optional, Dict from langchain_community.document_loaders.gitbook import GitbookLoader @@ -21,7 +21,7 @@ class GitbookLoaderComponent(CustomComponent): }, } - def build(self, metadata: Optional[Dict] = None, web_page: str = "") -> Document: + def build(self, metadata: Optional[Dict] = None, web_page: str = "") -> List[Document]: documents = GitbookLoader(web_page=web_page).load() if metadata: for document in documents: diff --git a/src/backend/langflow/components/documentloaders/HNLoader.py b/src/backend/langflow/components/documentloaders/HNLoader.py index 6e08f26e2..23f77d570 100644 --- a/src/backend/langflow/components/documentloaders/HNLoader.py +++ b/src/backend/langflow/components/documentloaders/HNLoader.py @@ -1,6 +1,7 @@ from langflow import CustomComponent -from typing import Optional, Dict +from typing import List, Optional, Dict from langchain_community.document_loaders.hn import HNLoader +from langflow.field_typing import Document class HNLoaderComponent(CustomComponent): @@ -17,7 +18,7 @@ class HNLoaderComponent(CustomComponent): self, web_path: str, metadata: Optional[Dict] = None, - ) -> HNLoader: + ) -> List[Document]: documents = HNLoader(web_path=web_path).load() if metadata: for document in documents: diff --git a/src/backend/langflow/components/documentloaders/IMSDbLoader.py b/src/backend/langflow/components/documentloaders/IMSDbLoader.py index 1eebcc444..bd16f854b 100644 --- a/src/backend/langflow/components/documentloaders/IMSDbLoader.py +++ b/src/backend/langflow/components/documentloaders/IMSDbLoader.py @@ -2,7 +2,7 @@ from langflow import CustomComponent from langflow.field_typing import Document from langchain_community.document_loaders.imsdb import IMSDbLoader -from typing import Dict, Optional +from typing import Dict, List, Optional class IMSDbLoaderComponent(CustomComponent): @@ -19,7 +19,7 @@ class IMSDbLoaderComponent(CustomComponent): self, metadata: Optional[Dict] = None, web_path: str = "", - ) -> Document: + ) -> List[Document]: documents = IMSDbLoader(web_path=web_path).load() if metadata: for document in documents: diff --git a/src/backend/langflow/components/documentloaders/TextLoader.py b/src/backend/langflow/components/documentloaders/TextLoader.py index 0c4033898..d3fa8e7ad 100644 --- a/src/backend/langflow/components/documentloaders/TextLoader.py +++ b/src/backend/langflow/components/documentloaders/TextLoader.py @@ -1,5 +1,5 @@ from langflow import CustomComponent -from langchain.data_connections import Document +from langflow.field_typing import Document from typing import Optional, Dict diff --git a/src/backend/langflow/components/embeddings/CohereEmbeddings.py b/src/backend/langflow/components/embeddings/CohereEmbeddings.py index 3fccc8c2c..4e7fb7b17 100644 --- a/src/backend/langflow/components/embeddings/CohereEmbeddings.py +++ b/src/backend/langflow/components/embeddings/CohereEmbeddings.py @@ -21,7 +21,7 @@ class CohereEmbeddingsComponent(CustomComponent): def build( self, request_timeout: Optional[float] = None, - cohere_api_key: str = None, + cohere_api_key: str = "", max_retries: Optional[int] = None, model: str = "embed-english-v2.0", truncate: Optional[str] = None, diff --git a/src/backend/langflow/components/embeddings/OpenAIEmbeddings.py b/src/backend/langflow/components/embeddings/OpenAIEmbeddings.py index 6838a7759..71bcb1db2 100644 --- a/src/backend/langflow/components/embeddings/OpenAIEmbeddings.py +++ b/src/backend/langflow/components/embeddings/OpenAIEmbeddings.py @@ -68,13 +68,13 @@ class OpenAIEmbeddingsComponent(CustomComponent): self, default_headers: Optional[Dict[str, str]] = None, default_query: Optional[NestedDict] = {}, - allowed_special: Optional[List[str]] = [], + allowed_special: List[str] = [], disallowed_special: List[str] = ["all"], - chunk_size: Optional[int] = 1000, + chunk_size: int = 1000, client: Optional[Any] = None, deployment: str = "text-embedding-ada-002", - embedding_ctx_length: Optional[int] = 8191, - max_retries: Optional[int] = 6, + embedding_ctx_length: int = 8191, + max_retries: int = 6, model: str = "text-embedding-ada-002", model_kwargs: NestedDict = {}, openai_api_base: Optional[str] = None, @@ -84,9 +84,9 @@ class OpenAIEmbeddingsComponent(CustomComponent): openai_organization: Optional[str] = None, openai_proxy: Optional[str] = None, request_timeout: Optional[float] = None, - show_progress_bar: Optional[bool] = False, - skip_empty: Optional[bool] = False, - tikToken_enable: Optional[bool] = True, + show_progress_bar: bool = False, + skip_empty: bool = False, + tikToken_enable: bool = True, tiktoken_model_name: Optional[str] = None, ) -> Union[OpenAIEmbeddings, Callable]: return OpenAIEmbeddings(