Commit graph

550 commits

Author SHA1 Message Date
Gabriel Luiz Freitas Almeida
265646ded3 🐛 fix(chat.py): change the prefix of the error message to 'data' to fix the server response
The error message prefix was changed from 'data' to 'error' to fix the server response.
2023-06-15 15:08:38 -03:00
Gabriel Luiz Freitas Almeida
03076b3577 🔨 refactor(flows.py): change response model of update_flow endpoint to FlowRead
🔨 refactor(parameterComponent): remove unused imports and refactor onChange function to handleOnNewValue
 feat(tabsContext): add tabsState and setTabsState to TabsContextType and TabsProvider
🔨 refactor(flowSettingsModal): refactor handleSaveFlow function to update flow and setTabsState with isPending false
The update_flow endpoint now returns a FlowRead response model instead of FlowReadWithStyle. The parameterComponent file has been refactored to remove unused imports and to use a handleOnNewValue function to handle onChange events. The TabsContextType and TabsProvider have been updated to include tabsState and setTabsState. The flowSettingsModal has been refactored to update the flow and setTabsState with isPending false.

🔨 refactor(extraSidebarComponent): add tabsState and setTabsState to TabsContextType
🐛 fix(extraSidebarComponent): disable save button when flow is not pending
🐛 fix(extraSidebarComponent): update flow state after saving
The TabsContextType now includes tabsState and setTabsState to allow for the management of the state of each tab. The save button is now disabled when the flow is not pending. The flow state is now updated after saving to reflect the changes made.
2023-06-15 15:08:37 -03:00
Gabriel Luiz Freitas Almeida
5ce9fa17cf 📝 docs(chains.py): update description of CombineDocsChainNode
The description of CombineDocsChainNode was updated to reflect the actual functionality of the node. The node is now used to load a question answering chain instead of constructing a chain from combined documents.
2023-06-15 11:40:29 -03:00
Gabriel Luiz Freitas Almeida
61a6710adf 🔒 chore(llms.py): set password field to False for fields not containing 'key' or 'token' in their name
The openai_api_version field value is no longer set as it is not needed. The password field is now set to False for fields not containing 'key' or 'token' in their name to improve security.
🐛 fix(llms.py): remove setting of openai_api_version field value
2023-06-15 09:45:15 -03:00
Gabriel Luiz Freitas Almeida
a23121aa54 🐛 fix(chat.py): yield error message when an exception occurs during stream_build
🔧 chore(base.py): fix typo in docstring
The fix in chat.py ensures that an error message is yielded when an exception occurs during stream_build. This helps to provide more information to the client-side when an error occurs. The typo in base.py's docstring is fixed to improve readability.
2023-06-15 07:44:11 -03:00
Gabriel Luiz Freitas Almeida
3920eb50d6 Merge remote-tracking branch 'origin/validation_fix' into db 2023-06-15 07:37:26 -03:00
Rodrigo Nader
fd59bd77b3 Refactor SQL agent and related nodes
- Rename `VectorStoreAgent` to `Vector store agent` in `custom.py`
- Replace "Construct a sql agent from an LLM and tools." with "Construct an SQL agent from an LLM and tools." in `custom.py`
- Update descriptions of `SQLAgentNode`, `TimeTravelGuideChainNode`, `CombineDocsChainNode`, and `ToolNode` in related files
- Increase width of `ExtraSidebarComponent` container in `index.tsx` from 52 to 56
2023-06-14 23:54:39 -03:00
anovazzi1
bba2942d37 format code 2023-06-14 19:33:21 -03:00
Gabriel Luiz Freitas Almeida
56b16dac60 🔨 refactor(documentloaders.py): move build_template function outside of DocumentLoaderFrontNode class
The build_template function is now outside of the DocumentLoaderFrontNode class to improve code organization and make it more modular. This change also makes it easier to reuse the function in other parts of the codebase.
2023-06-14 17:15:54 -03:00
Gabriel Luiz Freitas Almeida
010c1b7b50 Merge remote-tracking branch 'origin/NewId' into db 2023-06-14 14:56:46 -03:00
Gabriel Luiz Freitas Almeida
76cc488d79 🚀 feat(constants.py): add new OpenAI chat models and update existing ones
Added new OpenAI chat models to the CHAT_OPENAI_MODELS list to improve the quality of the chatbot responses. The new models are "gpt-3.5-turbo-0613", "gpt-3.5-turbo-16k-0613", "gpt-4-0613", and "gpt-4-32k-0613". The existing models "gpt-3.5-turbo" and "gpt-4-32k" were also updated to their latest versions.
2023-06-14 11:43:36 -03:00
Gabriel Luiz Freitas Almeida
676c92dd92 🎨 style(flows.py): add status codes to API endpoints
The status codes have been added to the API endpoints to improve the readability of the code and to make it more explicit what the expected response codes are. The status codes have been added to the following endpoints: create_flow, read_flows, read_flow, update_flow, delete_flow, create_flows, upload_file, and download_file.
2023-06-14 09:27:02 -03:00
Gabriel Luiz Freitas Almeida
7817c64591 🐛 fix(endpoints.py): change predict_flow function signature to include flow_id and session dependencies
 feat(endpoints.py): add flow_id parameter to predict_flow function to allow for running a flow by ID
The predict_flow function now includes a flow_id parameter and a session dependency to allow for running a flow by ID. The flow object is retrieved from the session using the flow_id parameter. If the flow is not found, a ValueError is raised.

🔨 refactor(constants.tsx): change API_URL constant to BASE_API_URL and add flow_id parameter to run_flow function
The API_URL constant has been renamed to BASE_API_URL to better reflect its purpose. The run_flow function now includes a flow_id parameter to allow for running a flow by ID. The flow_id parameter is used to construct the API URL.
2023-06-14 07:21:25 -03:00
Gabriel Luiz Freitas Almeida
9f5591639e 🐛 fix(chat.py): handle exceptions while building the flow and add a final response to the event stream
The code now handles exceptions that may occur while building the flow. A final response is added to the event stream to indicate the end of the stream.
2023-06-13 20:41:58 -03:00
Gabriel Luiz Freitas Almeida
8aac63b830 🐛 fix(chat.py): add try-except block to handle exceptions in init_build function
The try-except block was added to handle exceptions that may occur in the init_build function. If an exception occurs, it is logged and an HTTPException with a status code of 500 is returned. This ensures that the server does not crash and provides a more informative error message to the client.
2023-06-13 20:32:05 -03:00
Gabriel Luiz Freitas Almeida
044b01e6ad 🎨 style(chat.py): add status code 201 to init_build endpoint
The init_build endpoint now returns a status code of 201 to indicate that a new resource has been created. This improves the consistency of the API and makes it easier for clients to understand the response.
2023-06-13 20:23:44 -03:00
Gabriel Luiz Freitas Almeida
0259bf4acc 🎨 style(endpoints.py): rename get_load function to predict_flow for better semantics
The function name was changed to predict_flow to better reflect the functionality of the endpoint.
2023-06-13 19:53:00 -03:00
Gabriel Luiz Freitas Almeida
e07b7f546d
Update base.py 2023-06-13 17:31:53 -03:00
Gabriel Luiz Freitas Almeida
41f6aecda4 🔀 refactor(chat.py): import InitResponse and BuiltResponse from schemas module
🚀 feat(chat.py): add response models to /build/init and /build/{flow_id}/status endpoints
The InitResponse and BuiltResponse models are now imported from the schemas module to improve code organization. The /build/init and /build/{flow_id}/status endpoints now have response models to provide a clear understanding of the expected response.
2023-06-13 17:21:45 -03:00
Gabriel Luiz Freitas Almeida
90a1dd9795 🔧 chore(process.py): refactor process_tweaks function to improve readability and maintainability
The process_tweaks function has been refactored to improve readability and maintainability. The function now takes in two parameters, graph_data and tweaks, and returns the modified graph_data. The tweaks parameter is a dictionary of dictionaries, where the key is the node id and the value is a dictionary of the tweaks. The function processes the graph data to add the tweaks by iterating over the nodes and checking if the node id is in the tweaks dictionary. If it is, the function applies the tweaks to the node by updating the template data with the new values. The function also prints a message to the console to indicate that a tweak has been applied.
2023-06-13 12:49:22 -03:00
Gabriel Luiz Freitas Almeida
faf44eca0e 🔧 refactor(schemas.py): add optional tweaks field to PredictRequest schema
The PredictRequest schema now includes an optional tweaks field, which is a dictionary of dictionaries. This field allows for additional customization of the prediction request, such as specifying tool names or descriptions. The tweaks field is optional, and if not provided, the default value is an empty dictionary. The schema_extra attribute has also been updated to include an example of the new tweaks field.
2023-06-13 12:49:11 -03:00
Gabriel Luiz Freitas Almeida
7cc14e83b8 🚀 feat(endpoints.py): add authentication to predict endpoint using HTTPBearer
🐛 fix(endpoints.py): change predict endpoint to use Flow object instead of flow_id
🐛 fix(endpoints.py): add support for processing tweaks in predict endpoint
The predict endpoint now requires authentication using HTTPBearer. The flow_id is now extracted from the bearer token instead of being passed as a parameter. This improves security as the flow_id is not exposed in the URL. The predict endpoint now uses the Flow object instead of the flow_id to retrieve the graph data. This improves code readability and reduces the number of database queries. The predict endpoint now supports processing tweaks, which allows for more flexibility in the processing of messages.
2023-06-13 12:48:52 -03:00
Gabriel Luiz Freitas Almeida
d14be904ad 🐛 fix(chat.py): raise HTTPException instead of returning JSONResponse on stream_build error
The function stream_build was returning a JSONResponse with an error message when an exception was raised. This is not the correct way to handle errors in FastAPI. Instead, we should raise an HTTPException with the appropriate status code and error message.
2023-06-12 20:43:55 -03:00
Gabriel Luiz Freitas Almeida
d300c0b428 💄 style(chat.py): reformat code to improve readability
The unused imports and exception handling for WebSocketDisconnect and WebSocketException were removed from the chat.py file. The code was reformatted to improve readability.
🔥 refactor(chat.py): remove unused imports and exception handling
2023-06-12 20:40:43 -03:00
Gabriel Luiz Freitas Almeida
fe0c6f7f38 🐛 fix(chat.py): rename websocket_endpoint to chat for better semantics
 feat(chat.py): add build_status endpoint to check if flow_id is in flow_data_store
The function name websocket_endpoint was renamed to chat to improve semantics. The new build_status endpoint was added to check if a flow_id is in the flow_data_store. This endpoint returns a JSON response with a boolean value indicating whether the flow_id is built or not. If the flow_id is not in the flow_data_store, a JSON response with a value of False is returned. If an exception occurs, a 500 HTTPException is raised with the exception message as the detail.
2023-06-12 17:04:52 -03:00
Gabriel Luiz Freitas Almeida
585aeeab6e 🔥 refactor(base.py): remove unnecessary build method call in Graph class
The build method call in the for loop of the build_vertices method is unnecessary as the vertices are already sorted and built in the topological_sort method. The yield from statement is used to return the sorted vertices.
2023-06-12 13:05:27 -03:00
Gabriel Luiz Freitas Almeida
baeadf018d feat(chat.py): improve SSE response by adding node id and valid flag
The changes in this commit handle exceptions that may occur when creating a streaming response. The try-except block ensures that any exceptions are caught and an appropriate response is returned. Additionally, the SSE response has been improved by adding a valid flag and node id to the response. This provides more information to the client about the status of the node build and allows for better error handling.
🐛 fix(chat.py): handle exceptions when creating a streaming response
2023-06-12 13:03:46 -03:00
Gabriel Luiz Freitas Almeida
806d815a10 feat(index.tsx): add support for streaming build process using EventSource
The commented out code for the /build/{client_id} endpoint has been removed as it is no longer needed. The new implementation uses the /build/init endpoint to initiate the build process and then establishes an SSE connection using EventSource to stream the build process. This allows for a more efficient and responsive build process as the client can receive updates in real-time.
🔥 chore(chat.py, index.tsx): remove commented out code for /build/{client_id} endpoint
2023-06-12 11:49:59 -03:00
Gabriel Luiz Freitas Almeida
76f1aa8adf 🐛 fix(chat.py): add check for client_id in in_memory_cache before handling websocket
 feat(chat.py): add support for storing graph data and returning a unique session ID for building langchain object
 feat(chat.py): add support for streaming the build process based on stored flow data
The fix adds a check for the client_id in the in_memory_cache before handling the websocket. This ensures that the flow has been built before sending messages.

The first feature adds support for storing graph data and returning a unique session ID for building the langchain object. This allows the user to build the flow and then send messages.

The second feature adds support for streaming the build process based on stored flow data. This allows the user to see the progress of the build process.
2023-06-12 11:49:24 -03:00
Gabriel Luiz Freitas Almeida
6b57e20504 formatting 2023-06-12 09:45:28 -03:00
Gabriel Luiz Freitas Almeida
42d11894a2 🔀 chore(base.py): change return type of generator_build method from List[Vertex] to Generator
The return type of the generator_build method has been changed from List[Vertex] to Generator to improve the semantics of the method. The method now yields each vertex in the graph instead of returning a list of vertices.
2023-06-12 09:35:19 -03:00
Gabriel Luiz Freitas Almeida
a15cc30da5 🔥 refactor(manager.py): remove unused imports and dependencies
🔥 refactor(utils.py): remove unused imports and dependencies
The changes remove unused imports and dependencies from the codebase, which improves the code's readability and maintainability.
2023-06-12 09:33:54 -03:00
Gabriel Luiz Freitas Almeida
036818e9b9 🔧 refactor(chat.py): rename post_build to stream_build to improve semantics
🐛 fix(chat.py): fix generator_build method to yield node_repr and node_id
 feat(chat.py): add valid and id fields to error response to improve error handling
🔧 refactor(manager.py): change logger.exception to logger.error to log exceptions
🔧 refactor(graph/base.py): add logging to generator_build method to improve debugging
🔧 refactor(vertex/base.py): rename cache.base to cache.utils to improve semantics
The post_build method in chat.py was renamed to stream_build to better reflect its functionality. The generator_build method in graph/base.py was fixed to yield node_repr and node_id instead of node._built_object_repr() and node.id. The error response in chat.py now includes valid and id fields to improve error handling. logger.exception in manager.py was changed to logger.error to log exceptions. The generator_build method in graph/base.py now logs the sorted vertices to improve debugging. The cache.base module in vertex/base.py was renamed to cache.utils to better reflect its functionality.
2023-06-12 09:30:20 -03:00
Gabriel Luiz Freitas Almeida
273f452f7b 🔧 chore(chat.py): add SSE support to post_build endpoint
 feat(chat.py): add SSE support to post_build endpoint to stream build progress to the client
The post_build endpoint now returns a StreamingResponse object that streams Server-Sent Events (SSE) to the client. This allows the client to receive build progress updates in real-time. The event_stream function is responsible for generating the SSE events and is called by the StreamingResponse object. The SSE events contain information about the build progress, including whether the build was successful or not, the parameters used to build each node, and the node ID. The chat_manager.set_cache method is called to cache the built graph object.
2023-06-12 07:50:00 -03:00
Gabriel Luiz Freitas Almeida
76a49c8663 🐛 fix(manager.py): change status parameter type from status to int in close_connection method
🔥 refactor(manager.py): remove unused build method and rename set_cache to set_client_cache
🚀 chore(manager.py): add async keyword to close_connection method
The close_connection method now accepts an integer as the status parameter instead of a status enum. The build method was removed as it was not being used. The set_cache method was renamed to set_client_cache to improve semantics. The close_connection method was updated to be an async method.
2023-06-12 07:49:49 -03:00
Gabriel Luiz Freitas Almeida
9ebd02e331 🚀 feat(base.py): add topological_sort method to perform a topological sort of the vertices in the graph
🚀 feat(base.py): add generator_build method to build each node in the graph and yield it
The topological_sort method performs a topological sort of the vertices in the graph, returning a list of vertices in topological order. The generator_build method builds each node in the graph and yields it. These methods are useful for building the graph in a specific order, which is important for certain algorithms that rely on the order of the nodes.
2023-06-12 07:49:35 -03:00
Gabriel Luiz Freitas Almeida
f2e4a93df5 🐛 fix(base.py): remove unused import of logger
🎨 refactor(run.py): update import statement for compute_dict_hash, load_cache, and memoize_dict
The import of logger in base.py was not being used, so it was removed to improve code readability. In run.py, the import statement for compute_dict_hash, load_cache, and memoize_dict was updated to reflect the new location of these functions in the cache.utils module. This improves the organization of the code and makes it easier to find the relevant functions.
2023-06-11 18:08:20 -03:00
Gabriel Luiz Freitas Almeida
ccf9477b7f 🐛 fix(manager.py): add check for langchain object in process_message to avoid errors
 feat(manager.py): add build method to build langchain object and store it in an in-memory cache
The `process_message` method now checks if the langchain object has been built and stored in the in-memory cache before processing the message. If the object is not found, the connection is closed with an error message. A new `build` method has been added to build the langchain object and store it in an in-memory cache. This method is called before processing any messages.
2023-06-11 18:08:01 -03:00
Gabriel Luiz Freitas Almeida
dacc90d901 🐛 fix(cache/manager.py): change CACHE variable to _cache to follow naming conventions
 feat(cache/utils.py): add support for clearing old cache files and memoization of dictionary functions
The CACHE variable in CacheManager class has been renamed to _cache to follow naming conventions. The utils.py module now supports clearing old cache files and memoization of dictionary functions. The clear_old_cache_files function removes old cache files if the number of cache files exceeds the max_cache_size. The memoize_dict decorator memoizes dictionary functions and clears the cache when the clear_cache method is called.
2023-06-11 18:07:45 -03:00
Gabriel Luiz Freitas Almeida
02163cf775 feat(flow.py): add InMemoryCache class to implement an in-memory cache with LRU eviction policy
This commit adds a new class InMemoryCache to implement an in-memory cache with a Least Recently Used (LRU) eviction policy. The cache supports setting a maximum size and expiration time for cached items. The cache is thread-safe using a threading Lock. The InMemoryCache class inherits from the BaseCache class and implements the get, set, get_or_set, delete, clear, __contains__, __getitem__, __setitem__, __delitem__, __len__, and __repr__ methods.
2023-06-11 18:07:28 -03:00
Gabriel Luiz Freitas Almeida
a27e5d58dd 🔨 refactor(base.py): refactor BaseCache class to use abstract methods
This commit refactors the BaseCache class to use abstract methods instead of concrete methods. This makes the class more flexible and allows for different implementations of the cache. The abstract methods include get, set, delete, clear, __contains__, __getitem__, __setitem__, and __delitem__.
2023-06-11 18:07:17 -03:00
Gabriel Luiz Freitas Almeida
bdbc46f01d 🐛 fix(chat.py): add exception handling to post_build endpoint
 feat(cache/__init__.py): add InMemoryCache to exported modules
🔖 refactor(endpoints.py): remove unused import statement
The post_build endpoint in chat.py now has exception handling to catch any errors that may occur during the build process. InMemoryCache is now exported as part of the cache module. The endpoints.py file has been refactored to remove an unused import statement.
2023-06-11 18:06:57 -03:00
Gabriel Luiz Freitas Almeida
efbdd6fee7 🚀 feat(langflow): add version endpoint to API
🐛 fix(langflow): fix version import error in version endpoint
The version endpoint is added to the API to allow clients to retrieve the version of the Langflow package. The version is obtained using the `metadata.version` function from the `importlib` module. In case the package metadata is not available, an empty string is returned. The version endpoint was previously returning an error due to an import error. The error is fixed by importing the `__version__` variable from the `langflow` module.
2023-06-11 12:48:06 -03:00
Gabriel Luiz Freitas Almeida
0eaa86c5ca 🔧 chore(__main__.py): add support for loading environment variables from a .env file
The `load_dotenv` function from the `dotenv` package is now used to load environment variables from a `.env` file. This allows for a more flexible configuration of the application as environment variables can be loaded from a file instead of being hardcoded in the code. The `.env` file path can be specified via the `env_file` parameter.
2023-06-11 11:14:43 -03:00
Gabriel Luiz Freitas Almeida
cdbe2b0401 🐛 fix(endpoints.py): change graph_data variable to use flow_obj.data instead of flow_obj.flow
The graph_data variable was previously assigned to flow_obj.flow, which is incorrect as the flow_obj object does not have a flow attribute. Instead, the correct attribute to use is flow_obj.data.
2023-06-10 16:17:56 -03:00
Gabriel Luiz Freitas Almeida
bc07766575 🔊 chore(base.py): add logger to Graph class
🐛 fix(base.py): improve error message when invalid payload is received
The logger is added to the Graph class to improve debugging capabilities. The error message when an invalid payload is received is improved to include the keys that were found in the payload. This makes it easier to identify the issue and fix it.
2023-06-09 17:08:11 -03:00
Gabriel Luiz Freitas Almeida
bfb4a8e609 🔖 chore(base.py): add display_name field to FrontendNode
The `display_name` field is added to the `FrontendNode` class to allow for a more user-friendly name to be displayed in the UI. If `display_name` is not set, the `name` field will be used instead.
2023-06-09 17:08:01 -03:00
Gabriel Luiz Freitas Almeida
fdf24f269b
Merge branch 'dev' into agent_and_qa_chain 2023-06-09 16:25:29 -03:00
Gustavo Schaedler
8a08ebdbe7 Remove some commented out code + add condition for the execution of make publish 2023-06-09 20:09:25 +01:00
Alexandre Henrique Pereira Tavares
b02ed92b84
Implemented add_extra_fields method for the documentloaders (#408) 2023-06-09 15:24:56 -03:00