-
Notifications
You must be signed in to change notification settings - Fork 9k
refactor: load components by importing them directly #8395
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
Merged
Merged
Changes from all commits
Commits
Show all changes
94 commits
Select commit
Hold shift + click to select a range
17d475c
refactor: update default behavior for components path in Settings class
ogabrielluiz a762ae4
feat: Implement importing of Langflow components
ogabrielluiz 4cff048
feat: Enhance component handling in custom utils for better flexibility
ogabrielluiz 7232284
refactor: Simplify component retrieval logic and enhance error handling
ogabrielluiz 785d08e
refactor: Remove unnecessary 'required_inputs' field from multiple st…
ogabrielluiz 64536d9
refactor: Change error handling to warning for component instantiatio…
ogabrielluiz 9f485d9
refactor: Improve component type checking in get_component_instance a…
ogabrielluiz b28924f
refactor: Update subclass check for custom_component in run_build_con…
ogabrielluiz 8586823
refactor: Update component name retrieval logic to prioritize class name
ogabrielluiz ea21d59
refactor: Replace settings service call with direct BASE_COMPONENTS_P…
ogabrielluiz 9c86542
refactor: Update required inputs and improve model name info across s…
ogabrielluiz f0215d6
[autofix.ci] apply automated fixes
autofix-ci[bot] fd83816
📝 Add docstrings to `fix-component-loading` (#8397)
coderabbitai[bot] 31b8eed
Build and log fixes
jordanrfrazier c1a5c9f
refactor: Improve type checking for custom component instances in `ge…
ogabrielluiz 2a49275
refactor: Enhance type checking for custom components in `run_build_c…
ogabrielluiz fcc6c01
refactor: Clean up docstrings in component loading functions for clarity
ogabrielluiz 04eff15
refactor: Rename `get_langflow_components_list` to `import_langflow_c…
ogabrielluiz c2aecda
refactor: Exclude deactivated modules and improve class checking in c…
ogabrielluiz 9ca8a28
test: Add component differences analysis for import_langflow_componen…
ogabrielluiz 5482318
[autofix.ci] apply automated fixes
autofix-ci[bot] 6af4909
refactor: Simplify assert statements and improve logging in component…
ogabrielluiz ca32307
[autofix.ci] apply automated fixes
autofix-ci[bot] 6bc04ba
refactor: Consolidate __all__ declaration for retriever components
ogabrielluiz 2faf03e
refactor: Improve comments for clarity in run_build_config function
ogabrielluiz 5e57bee
Merge branch 'main' into fix-component-loading
jordanrfrazier 36a1077
[autofix.ci] apply automated fixes
autofix-ci[bot] f814ba6
refactor: Enhance module validation logic in _get_langflow_components…
ogabrielluiz 4bf78dc
refactor: Update debug log message for clarity in get_and_cache_all_t…
ogabrielluiz 5dac3e5
refactor: Enhance parallel processing of Langflow components import a…
ogabrielluiz 26a8d69
refactor: Improve performance testing by adding warm-up runs and clar…
ogabrielluiz cacf7ff
refactor: Improve assertion clarity in component loading tests and ad…
ogabrielluiz 1a75971
[autofix.ci] apply automated fixes
autofix-ci[bot] 516a37a
[autofix.ci] apply automated fixes (attempt 2/3)
autofix-ci[bot] 232809c
[autofix.ci] apply automated fixes (attempt 3/3)
autofix-ci[bot] 2fd61f9
Use Component base class instead of custom component for a few compon…
jordanrfrazier 6a529c3
⚡️ Speed up function `get_component_instance` by 365% in PR #8395 (`f…
codeflash-ai[bot] 6222405
[autofix.ci] apply automated fixes
autofix-ci[bot] 38f514b
[autofix.ci] apply automated fixes (attempt 2/3)
autofix-ci[bot] 1ca5f80
refactor: update debug log message for components cache building
ogabrielluiz b4c350a
refactor: update required inputs to use 'api_key' for multiple starte…
ogabrielluiz 3479168
refactor: update import statement for BaseFileComponent in nvidia_ing…
ogabrielluiz 235ea72
refactor: simplify timing results print statement in test_load_compon…
ogabrielluiz 9ecf621
[autofix.ci] apply automated fixes
autofix-ci[bot] 11ebd23
[autofix.ci] apply automated fixes (attempt 2/3)
autofix-ci[bot] b03f7b4
refactor: improve assertion readability and error handling in test_lo…
ogabrielluiz 29148d1
[autofix.ci] apply automated fixes
autofix-ci[bot] 38e095d
[autofix.ci] apply automated fixes (attempt 2/3)
autofix-ci[bot] 7c1f493
[autofix.ci] apply automated fixes (attempt 3/3)
autofix-ci[bot] a3516ff
feat: allow os.stat in pkgutil for component loading in blockbuster f…
ogabrielluiz e1ed5e8
[autofix.ci] apply automated fixes
autofix-ci[bot] ec6389b
[autofix.ci] apply automated fixes (attempt 2/3)
autofix-ci[bot] e348334
[autofix.ci] apply automated fixes (attempt 3/3)
autofix-ci[bot] 2cad1f6
updates few components to new template
jordanrfrazier 5e75980
import fixes
jordanrfrazier 18e5663
[autofix.ci] apply automated fixes
autofix-ci[bot] 16d3bdd
[autofix.ci] apply automated fixes (attempt 2/3)
autofix-ci[bot] 07af9ed
[autofix.ci] apply automated fixes (attempt 3/3)
autofix-ci[bot] 110baf7
remove unused VectaraSelfQueryRetriverComponent from vectorstores __a…
ogabrielluiz 0fb2016
Update starter project configurations to require 'api_key' as a manda…
ogabrielluiz 9f72055
[autofix.ci] apply automated fixes
autofix-ci[bot] 276d06f
Refactor JSONDocumentBuilder by removing TYPE_CHECKING import and upd…
ogabrielluiz 6d139d7
⚡️ Speed up function `_process_single_module` by 1,017% in PR #8395 (…
codeflash-ai[bot] 5e1685a
[autofix.ci] apply automated fixes
autofix-ci[bot] 03cffd7
Remove unnecessary call to `_set_output_required_inputs` in `Componen…
ogabrielluiz cc7b253
Revert "Use Component base class instead of custom component for a fe…
ogabrielluiz 0aa17a2
move components to deactivated folder
ogabrielluiz 09176d2
[autofix.ci] apply automated fixes
autofix-ci[bot] 2d3b664
Merge branch 'main' into fix-component-loading
ogabrielluiz c2178b7
Revert "move components to deactivated folder"
ogabrielluiz 661e1e3
Implement multiple new components in the deactivated folder, includin…
ogabrielluiz fc130e2
feat: Enhance starter project loading with improved logging and error…
ogabrielluiz 47cc0d2
refactor: Remove debug logging for module processing in import_langfl…
ogabrielluiz 90777c7
[autofix.ci] apply automated fixes
autofix-ci[bot] 05bede7
fix: Disable mypy error for undefined attributes in deactivated compo…
ogabrielluiz f474c36
feat: Enhance blocking behavior in blockbuster tests with additional …
ogabrielluiz 93d76c7
fix: Add import error handling for boto3 in S3BucketUploaderComponent
ogabrielluiz 505d4b4
refactor: Add debug logging for module processing in components
ogabrielluiz 3ad4e4e
fix: Temporarily disable auto-use for blockbuster fixture until block…
ogabrielluiz 2236488
feat: Add utility function to check for preimported components
ogabrielluiz 84b60d5
fix: Update get_component_instance to accept both CustomComponent and…
ogabrielluiz 2e23ba2
fix: Update import error message for boto3 installation instructions
ogabrielluiz 3165d2a
fix: Correct class name from VectoStoreRetrieverComponent to VectorSt…
ogabrielluiz d9b51e2
fix: Update Vectara type hints and import statements for consistency
ogabrielluiz 20b2f05
fix: Refactor get_component_instance and build_custom_component_templ…
ogabrielluiz aec8f8a
Merge branch 'main' into fix-component-loading
ogabrielluiz 8bfd09e
fix: Remove debug logging from _process_single_module to streamline m…
ogabrielluiz e1627bc
⚡️ Speed up function `is_a_preimported_component` by 24% in PR #8395 …
codeflash-ai[bot] 2ee4d92
✨ (freeze.spec.ts): introduce new function addFlowToTestOnEmptyLangfl…
Cristhianzl c506398
Merge branch 'main' into fix-component-loading
ogabrielluiz d87837f
merge fix
Cristhianzl 6879a33
merge fix
Cristhianzl b7027ca
✨ (freeze.spec.ts): increase timeout value for waiting for "built suc…
Cristhianzl 5654676
✨ (freeze.spec.ts): refactor code to check if firstRunLangflow is gre…
Cristhianzl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
src/backend/base/langflow/components/deactivated/amazon_kendra.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| # mypy: disable-error-code="attr-defined" | ||
| from langchain_community.retrievers import AmazonKendraRetriever | ||
|
|
||
| from langflow.base.vectorstores.model import check_cached_vector_store | ||
| from langflow.custom.custom_component.custom_component import CustomComponent | ||
| from langflow.io import DictInput, IntInput, StrInput | ||
|
|
||
|
|
||
| class AmazonKendraRetrieverComponent(CustomComponent): | ||
| display_name: str = "Amazon Kendra Retriever" | ||
| description: str = "Retriever that uses the Amazon Kendra API." | ||
| name = "AmazonKendra" | ||
| icon = "Amazon" | ||
| legacy = True | ||
|
|
||
| inputs = [ | ||
| StrInput( | ||
| name="index_id", | ||
| display_name="Index ID", | ||
| ), | ||
| StrInput( | ||
| name="region_name", | ||
| display_name="Region Name", | ||
| ), | ||
| StrInput( | ||
| name="credentials_profile_name", | ||
| display_name="Credentials Profile Name", | ||
| ), | ||
| DictInput( | ||
| name="attribute_filter", | ||
| display_name="Attribute Filter", | ||
| ), | ||
| IntInput( | ||
| name="top_k", | ||
| display_name="Top K", | ||
| value=3, | ||
| ), | ||
| DictInput( | ||
|
ogabrielluiz marked this conversation as resolved.
|
||
| name="user_context", | ||
| display_name="User Context", | ||
| ), | ||
| ] | ||
|
|
||
| @check_cached_vector_store | ||
| def build_vector_store(self) -> AmazonKendraRetriever: | ||
| """Builds the Amazon Kendra Retriever.""" | ||
| try: | ||
| from langchain_community.retrievers import AmazonKendraRetriever | ||
| except ImportError as e: | ||
| msg = "Could not import AmazonKendraRetriever. Please install it with `pip install langchain-community`." | ||
| raise ImportError(msg) from e | ||
|
|
||
| try: | ||
| output = AmazonKendraRetriever( | ||
| index_id=self.index_id, | ||
| top_k=self.top_k, | ||
| region_name=self.region_name, | ||
| credentials_profile_name=self.credentials_profile_name, | ||
| attribute_filter=self.attribute_filter, | ||
| user_context=self.user_context, | ||
| ) | ||
| except Exception as e: | ||
| msg = "Could not connect to AmazonKendra API." | ||
| raise ValueError(msg) from e | ||
|
|
||
| return output | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| # mypy: disable-error-code="attr-defined" | ||
| from langchain_community.retrievers import MetalRetriever | ||
|
|
||
| from langflow.base.vectorstores.model import check_cached_vector_store | ||
| from langflow.custom.custom_component.custom_component import CustomComponent | ||
| from langflow.io import DictInput, SecretStrInput, StrInput | ||
|
ogabrielluiz marked this conversation as resolved.
|
||
|
|
||
|
|
||
| class MetalRetrieverComponent(CustomComponent): | ||
| display_name: str = "Metal Retriever" | ||
| description: str = "Retriever that uses the Metal API." | ||
| name = "MetalRetriever" | ||
| legacy = True | ||
|
|
||
| inputs = [ | ||
| SecretStrInput( | ||
| name="api_key", | ||
| display_name="API Key", | ||
| required=True, | ||
| ), | ||
| SecretStrInput( | ||
| name="client_id", | ||
| display_name="Client ID", | ||
| required=True, | ||
| ), | ||
| StrInput( | ||
| name="index_id", | ||
| display_name="Index ID", | ||
| required=True, | ||
| ), | ||
| DictInput( | ||
| name="params", | ||
| display_name="Parameters", | ||
| required=False, | ||
| ), | ||
| ] | ||
|
ogabrielluiz marked this conversation as resolved.
|
||
|
|
||
| @check_cached_vector_store | ||
| def build_vector_store(self) -> MetalRetriever: | ||
| """Builds the Metal Retriever.""" | ||
| try: | ||
| from langchain_community.retrievers import MetalRetriever | ||
| from metal_sdk.metal import Metal | ||
| except ImportError as e: | ||
| msg = "Could not import Metal. Please install it with `pip install metal-sdk langchain-community`." | ||
| raise ImportError(msg) from e | ||
|
|
||
| try: | ||
| metal = Metal(api_key=self.api_key, client_id=self.client_id, index_id=self.index_id) | ||
| except Exception as e: | ||
| msg = "Could not connect to Metal API." | ||
| raise ValueError(msg) from e | ||
|
|
||
| return MetalRetriever(client=metal, params=self.params or {}) | ||
59 changes: 59 additions & 0 deletions
59
src/backend/base/langflow/components/deactivated/multi_query.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| from langchain.prompts import PromptTemplate | ||
| from langchain.retrievers import MultiQueryRetriever | ||
|
|
||
| from langflow.custom.custom_component.custom_component import CustomComponent | ||
| from langflow.field_typing import BaseRetriever, LanguageModel, Text | ||
| from langflow.inputs.inputs import HandleInput, StrInput | ||
|
|
||
|
|
||
| class MultiQueryRetrieverComponent(CustomComponent): | ||
| display_name = "MultiQueryRetriever" | ||
| description = "Initialize from llm using default template." | ||
| documentation = "https://python.langchain.com/docs/modules/data_connection/retrievers/how_to/MultiQueryRetriever" | ||
| name = "MultiQueryRetriever" | ||
| legacy = True | ||
|
|
||
| inputs = [ | ||
| HandleInput( | ||
| name="llm", | ||
| display_name="LLM", | ||
| input_types=["LanguageModel"], | ||
| required=True, | ||
| ), | ||
| HandleInput( | ||
| name="retriever", | ||
| display_name="Retriever", | ||
| input_types=["BaseRetriever"], | ||
| required=True, | ||
| ), | ||
| StrInput( | ||
| name="prompt", | ||
| display_name="Prompt", | ||
| value="You are an AI language model assistant. Your task is \n" | ||
| "to generate 3 different versions of the given user \n" | ||
| "question to retrieve relevant documents from a vector database. \n" | ||
| "By generating multiple perspectives on the user question, \n" | ||
| "your goal is to help the user overcome some of the limitations \n" | ||
| "of distance-based similarity search. Provide these alternative \n" | ||
| "questions separated by newlines. Original question: {question}", | ||
| required=False, | ||
| ), | ||
| StrInput( | ||
| name="parser_key", | ||
| display_name="Parser Key", | ||
| value="lines", | ||
| required=False, | ||
| ), | ||
| ] | ||
|
|
||
| def build( | ||
| self, | ||
| llm: LanguageModel, | ||
| retriever: BaseRetriever, | ||
| prompt: Text | None = None, | ||
| parser_key: str = "lines", | ||
| ) -> MultiQueryRetriever: | ||
| if not prompt: | ||
| return MultiQueryRetriever.from_llm(llm=llm, retriever=retriever, parser_key=parser_key) | ||
| prompt_template = PromptTemplate.from_template(prompt) | ||
| return MultiQueryRetriever.from_llm(llm=llm, retriever=retriever, prompt=prompt_template, parser_key=parser_key) |
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
src/backend/base/langflow/components/deactivated/vectara_self_query.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| # mypy: disable-error-code="attr-defined" | ||
| import json | ||
|
|
||
| from langchain.chains.query_constructor.base import AttributeInfo | ||
| from langchain.retrievers.self_query.base import SelfQueryRetriever | ||
|
|
||
| from langflow.base.vectorstores.model import check_cached_vector_store | ||
| from langflow.custom.custom_component.custom_component import CustomComponent | ||
| from langflow.io import HandleInput, StrInput | ||
|
|
||
|
|
||
| class VectaraSelfQueryRetriverComponent(CustomComponent): | ||
|
ogabrielluiz marked this conversation as resolved.
|
||
| """A custom component for implementing Vectara Self Query Retriever using a vector store.""" | ||
|
|
||
| display_name: str = "Vectara Self Query Retriever" | ||
| description: str = "Implementation of Vectara Self Query Retriever" | ||
| name = "VectaraSelfQueryRetriver" | ||
| icon = "Vectara" | ||
| legacy = True | ||
|
|
||
| inputs = [ | ||
| HandleInput( | ||
| name="vectorstore", | ||
| display_name="Vector Store", | ||
| info="Input Vectara Vector Store", | ||
| ), | ||
| HandleInput( | ||
| name="llm", | ||
| display_name="LLM", | ||
| info="For self query retriever", | ||
| ), | ||
| StrInput( | ||
| name="document_content_description", | ||
| display_name="Document Content Description", | ||
| info="For self query retriever", | ||
| ), | ||
| StrInput( | ||
| name="metadata_field_info", | ||
| display_name="Metadata Field Info", | ||
| info="Each metadata field info is a string in the form of key value pair dictionary containing " | ||
| "additional search metadata.\n" | ||
| 'Example input: {"name":"speech","description":"what name of the speech","type":' | ||
| '"string or list[string]"}.\n' | ||
| "The keys should remain constant(name, description, type)", | ||
| ), | ||
| ] | ||
|
|
||
| @check_cached_vector_store | ||
| def build_vector_store(self): | ||
| """Builds the Vectara Self Query Retriever.""" | ||
| try: | ||
| from langchain_community.vectorstores import Vectara # noqa: F401 | ||
| except ImportError as e: | ||
| msg = "Could not import Vectara. Please install it with `pip install langchain-community`." | ||
| raise ImportError(msg) from e | ||
|
|
||
| metadata_field_obj = [] | ||
| for meta in self.metadata_field_info: | ||
| meta_obj = json.loads(meta) | ||
| if "name" not in meta_obj or "description" not in meta_obj or "type" not in meta_obj: | ||
| msg = "Incorrect metadata field info format." | ||
| raise ValueError(msg) | ||
|
ogabrielluiz marked this conversation as resolved.
|
||
| attribute_info = AttributeInfo( | ||
| name=meta_obj["name"], | ||
| description=meta_obj["description"], | ||
| type=meta_obj["type"], | ||
| ) | ||
| metadata_field_obj.append(attribute_info) | ||
|
|
||
| return SelfQueryRetriever.from_llm( | ||
| self.llm, # noqa: ignore[attr-defined] | ||
| self.vectorstore, # noqa: ignore[attr-defined] | ||
| self.document_content_description, # noqa: ignore[attr-defined] | ||
| metadata_field_obj, | ||
| verbose=True, | ||
| ) | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.