Commit graph

24 commits

Author SHA1 Message Date
gustavoschaedler
839e9737cc Refactor code to extract class name from custom code
- Updatethe `get_function_custom` function to use the `validate.extract_class_name` function to extract class name from the `code` parameter.
- Modify `instantiate_tool` function to update the `class_object` with the return value of `get_function_custom` and call the `build` method on the instantiated object with the remaining params.
- Add a new function `extract_class_name` in the `validate` module to extract class name from the `code` parameter.
2023-07-05 03:34:16 +01:00
gustavoschaedler
92b747b6da Update Vertex params with code type and add a my_conversation method to the MyPythonClass. Modify the instantiate_tool function to properly handle the CustomComponent node type. Add a dynamic field to the FrontendNode class. 2023-07-05 00:46:51 +01:00
gustavoschaedler
13bb0280f5 [extract_info_from_class.py] Remove unnecessary code
This commit removes the file `extract_info_from_class.py` which contained unnecessary code.

[v1/endpoints.py] Fix error handling in custom_component endpoint

This commit fixes the error handling in the `custom_component` endpoint in `endpoints.py`. If the class template extracted from the code is not valid, an error message is printed.

[importing/utils.py] Comment out unused code

This commit comments out unused code in `get_function_custom` function in `utils.py` file.

[initialize/loading.py] Comment out unused code

This commit comments out unused code in the `instantiate_tool` function in `loading.py` file.

[interface/tools/custom.py] Refactor code and add properties

This commit refactors the code in `CustomComponent` class in `custom.py` file. It adds properties for `data`, `is_valid`, and `args_and_return_type`.

[interface/types.py] Add base classes to custom component template

This commit adds base classes to the custom component template in the `build_langchain_template_custom_component` function in `types.py` file.

[utils/constants.py] Remove unnecessary import

This commit removes an unnecessary import in `DEFAULT_CUSTOM_COMPONENT_CODE` constant in `constants.py` file.
2023-07-04 21:00:02 +01:00
gustavoschaedler
6416c43ff2 Merge remote-tracking branch 'origin/form_io' into python_custom_node_component 2023-06-30 16:44:11 +01:00
Gabriel Luiz Freitas Almeida
0eead8f3f7 🐛 fix(loading.py): fix condition to check for "handle_keys" in format_kwargs instead of params
The condition to check for the presence of "handle_keys" has been fixed to correctly check for its existence in the format_kwargs dictionary instead of the params dictionary. This ensures that the "handle_keys" list is properly populated when necessary.
2023-06-30 11:23:19 -03:00
Gabriel Luiz Freitas Almeida
270d5fb106 🐛 fix(loading.py): add missing condition to check if variable is an instance of BaseOutputParser and has "get_format_instructions" attribute
The code was missing a condition to check if the variable is an instance of BaseOutputParser and has the "get_format_instructions" attribute. This condition is necessary to properly handle the variable and avoid potential errors.
2023-06-30 11:17:32 -03:00
Gabriel Luiz Freitas Almeida
e98e0b22df 🐛 fix(vertex/base.py): add input types from template_dicts to optional_inputs
🐛 fix(interface/initialize/loading.py): handle BaseOutputParser instances in instantiate_prompt
The `optional_inputs` list in the `Vertex` class is now extended with the `input_types` from the `template_dicts` dictionary. This ensures that the `optional_inputs` list contains all the input types that are not required. In the `instantiate_prompt` function, if the `variable` is an instance of `BaseOutputParser` and has a `get_format_instructions` method, the `format_kwargs` dictionary is updated with the result of calling `get_format_instructions()`. This allows handling `BaseOutputParser` instances correctly in the `instantiate_prompt` function.
2023-06-29 20:43:22 -03:00
gustavoschaedler
dd009a2913 feat: Add support for Custom Component in Langflow Interface
This commit adds support for Custom Component in the Langflow interface. It introduces a new class `CustomComponent`, which takes in a `code` as a parameter and validates it. The `CustomComponent` class also provides a method to get the function specified in the code.

The commit also makes some modifications in `initialize/loading.py` file to handle the new `CustomComponent` class. It adds a new helper function `get_function_custom` which creates a function using `validate.create_function` and the `build` function name.
2023-06-30 00:23:50 +01:00
Gabriel Luiz Freitas Almeida
1743edfd1d 🐛 fix(loading.py): handle case when "handle_keys" is not in params dictionary and add input_variable to "handle_keys" list
The code now checks if the "handle_keys" key is present in the params dictionary. If it is not present, it creates an empty list and adds the input_variable to it. This ensures that the "handle_keys" list is always present and the input_variable is correctly added to it.
2023-06-29 19:31:01 -03:00
Gabriel Luiz Freitas Almeida
5e00debae4 🔧 fix(utils.py): add import statement for output_parsers module
🔧 fix(loading.py): add import statement for output_parser_creator
🔧 fix(listing.py): add import statement for output_parser_creator
🔧 fix(types.py): add import statement for output_parser_creator
The import statements for the `output_parsers` module were missing in the respective files. This fix adds the necessary import statements to ensure that the `output_parser_creator` is accessible and can be used in the code.
2023-06-29 12:56:36 -03:00
Gabriel Luiz Freitas Almeida
2876afa79a 🐛 fix(loading.py): fix formatting of input variables in instantiate_prompt function
The instantiate_prompt function now properly formats the input variables before passing them to the prompt object. If the input variable is a string, it is passed as is. If the input variable is a list of Document objects, it is formatted to contain the page_content and metadata as one string separated by a newline. This ensures that the prompt object receives the correct input format.
2023-06-29 11:44:51 -03:00
gustavoschaedler
82b76840e3 feat: Add CustomComponent tool to Langflow API
- Added support for the CustomComponent tool in the Langflow API.
- The tool has been added to the config.yaml file.
- The CustomComponentNode class has been implemented in the frontend nodes.
- The code changes include modifications in various files for the implementation of the CustomComponent tool.
- The code changes include the addition of a new field "code" in the TemplateField class.
- The build_langchain_template_custom_component function has been implemented to build the template for the CustomComponent tool.
- New custom fields "my_id", "year", and "other_field" have been added to the template for the CustomComponent tool.
2023-06-29 01:57:53 +01:00
Gabriel Luiz Freitas Almeida
a445b079e0 🔧 refactor(loading.py): simplify instantiation of prompt and format_kwargs assignment
💡 chore(loading.py): improve code readability and maintainability by simplifying the instantiation of the prompt object and assignment of format_kwargs dictionary.

The code has been refactored to use a dictionary comprehension to create the format_kwargs dictionary. This simplifies the logic and improves code readability. The commented out code for the prompt.partial() method has been removed as it is no longer necessary.
2023-06-28 17:59:57 -03:00
Gabriel Luiz Freitas Almeida
03349bf999 🐛 fix(vertex/base.py): add artifacts attribute to Vertex class to store additional data
🐛 fix(vertex/base.py): update instantiation logic to handle tuple result from loading.instantiate_class()
🐛 fix(loading.py): update return value of instantiate_prompt() to return a tuple of prompt and format_kwargs
The Vertex class now has a new attribute called artifacts, which is a dictionary used to store additional data related to the vertex. The instantiation logic in the Vertex class has been updated to handle the case where loading.instantiate_class() returns a tuple containing the built object and additional artifacts. The loading.instantiate_prompt() function now returns a tuple containing the prompt and format_kwargs. These changes fix issues related to storing and handling additional data in the vertex and loading modules.
2023-06-28 17:26:57 -03:00
Gabriel Luiz Freitas Almeida
a0919cb649 🐛 fix(validate.py): set "input_variables" field to new list of variables if it exists
🐛 fix(loading.py): set input variable values if they are present in params
The "input_variables" field in the prompt's frontend_node template is now updated with the new list of variables, if it exists. This ensures that the input variables are correctly set when validating the prompt. In the loading module, the input variable values are now set if they are present in the params dictionary. This ensures that the prompt is correctly instantiated with the provided input variable values.
2023-06-28 16:43:51 -03:00
Gabriel Luiz Freitas Almeida
8107f9e332 feat(loading.py): add support for new prompt templates in instantiate_prompt function
The config.yaml file has been updated to include new prompt templates. In types.py, the input_variables list was not being cleared when prompt or messages were present, which has been fixed. The instantiate_prompt function in loading.py has been updated to support the new prompt templates.
🔀 chore(config): add new prompt templates to config.yaml
🐛 fix(types.py): fix input_variables not being cleared when prompt or messages are present
2023-06-27 12:06:23 -03:00
Gabriel Luiz Freitas Almeida
d9ec262752 formatting 2023-06-23 16:51:54 -03:00
Gabriel Luiz Freitas Almeida
15ac75ecc5 🔨 refactor(loading.py): add support for filtering files by extension in document loader
The `instantiate_documentloader` function now supports filtering files by extension using a `file_filter` parameter. The parameter is a string of comma-separated extensions, and the function now converts it into a lambda function that filters files based on whether their name contains any of the specified extensions. This improves the flexibility of the document loader by allowing it to load only specific types of files.
2023-06-23 16:50:11 -03:00
Gabriel Luiz Freitas Almeida
99121d95c1 🔀 refactor(loading.py): use dictionary to initialize vector stores
The `instantiate_vectorstore` function now uses a dictionary to initialize vector stores instead of a series of if-else statements. This improves the readability and maintainability of the code. A new dictionary `vecstore_initializer` is added to `vector_store.py` to map the class names of vector stores to their respective initialization functions.
2023-06-23 14:32:15 -03:00
Gabriel Luiz Freitas Almeida
fb7bcb50e5 🚀 feat(loading.py): add support for MongoDBAtlasVectorSearch vector store
The `instantiate_vectorstore` function now supports the `MongoDBAtlasVectorSearch` vector store. This allows for the use of MongoDB Atlas as a vector store for Langflow. The `search_kwargs` parameter is now supported for all vector stores that have a `as_retriever` method. This allows for the configuration of the vector store's search parameters.
2023-06-23 13:20:02 -03:00
Gabriel Luiz Freitas Almeida
bcb80a08b2 🐛 fix(loading.py): remove unnecessary type hinting for allowed_tools variable
The type hinting for allowed_tools variable is unnecessary as it is already defined in the previous line. Removing the type hinting improves the readability of the code.
2023-06-23 11:04:03 -03:00
Gabriel Luiz Freitas Almeida
fb25744714 🔥 refactor(loading.py): remove unused imports and functions
The imports and functions that were not being used were removed to improve the code's readability and maintainability.
2023-06-23 10:51:09 -03:00
Gabriel Luiz Freitas Almeida
6fc57bff5e 🚀 feat(loading.py): add support for initializing new vector store types
🚀 feat(vector_store.py): add support for initializing SupabaseVectorStore
This commit adds support for initializing new vector store types in the loading.py file. Specifically, the initialize_weaviate, initialize_faiss, and initialize_supabase functions were added to support the Weaviate, FAISS, and SupabaseVectorStore vector stores, respectively. The vector_store.py file was also updated to include the SupabaseVectorStore class and the initialize_supabase function. This allows for more flexibility in choosing vector stores for the application.
2023-06-22 21:01:11 -03:00
Gabriel Luiz Freitas Almeida
b8141dca7d 🚀 feat(loading.py): move loading into initialize module
📝 docs(initialize): add empty __init__.py file to initialize directory
The initialize directory was added to the project, but it was missing an __init__.py file. This file is necessary to make the directory a package and allow importing modules from it. An empty __init__.py file was added to the directory to fix this issue.
2023-06-22 13:45:04 -03:00
Renamed from src/backend/langflow/interface/loading.py (Browse further)