Commit graph

1,840 commits

Author SHA1 Message Date
anovazzi1
8affac1f53 Merge branch 'validation_fix' of personal:logspace-ai/langflow into validation_fix 2023-06-13 20:43:22 -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
anovazzi1
b55d24101d Merge branch 'validation_fix' of personal:logspace-ai/langflow into validation_fix 2023-06-13 20:32:37 -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
anovazzi1
0b4925bddf Merge branch 'validation_fix' of personal:logspace-ai/langflow into validation_fix 2023-06-13 20:24:38 -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
anovazzi1
78faae8372 Merge branch 'validation_fix' of personal:logspace-ai/langflow into validation_fix 2023-06-13 20:01:02 -03:00
Gabriel Luiz Freitas Almeida
af8afea421 🚀 feat(chatComponent): update API endpoint for build stream
🚀 feat(vite.config.ts): add new API route for build stream
The API endpoint for the build stream has been updated to `/api/v1/build/stream/${flowId}` to improve consistency with the naming conventions. The `vite.config.ts` file has been updated to include the new API route for the build stream.
2023-06-13 19:42:30 -03:00
anovazzi1
1a6406e394 Merge branch 'validation_fix' of personal:logspace-ai/langflow into validation_fix 2023-06-13 18:45:57 -03:00
anovazzi1
86751e0daf added try catch block on streamNodeData 2023-06-13 18:45:42 -03:00
Gabriel Luiz Freitas Almeida
ebf5568db0 🐛 fix(App.tsx): change fetch URL to match backend API endpoint
The fetch URL was changed to match the backend API endpoint. The previous URL was incorrect and caused the fetch request to fail.
2023-06-13 18:08:01 -03:00
Gabriel Luiz Freitas Almeida
52baae64e6 🔨 refactor(chatComponent): remove unused imports and variables, and extract postBuildInit function to API controller
 feat(API): add postBuildInit function to handle POST requests to /api/v1/build/init
The chatComponent file had unused imports and variables that were removed to improve code readability. The postBuildInit function was extracted to the API controller to improve code organization and maintainability. The function handles POST requests to /api/v1/build/init.
2023-06-13 18:05:11 -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
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
7b44b18726 🐛 fix(loading.tsx): fix broken link to the source of the Loading component
The React import is not used in the file, so it has been removed to improve code readability. The link to the source of the Loading component was broken, so it has been fixed to ensure that the component can be used properly.
🔥 chore(loading.tsx): remove unused React import
2023-06-12 20:40:44 -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
anovazzi1
a41cc95abb added security check to avoid errors on building empty flows 2023-06-12 20:26:56 -03:00
anovazzi1
62b0b28b7f start websocket from chat only after build 2023-06-12 20:23:52 -03:00
anovazzi1
f9cece1ece lock click on loading state of button 2023-06-12 20:10:40 -03:00
anovazzi1
1fdf03c925 validating nodes before sending it to the backend 2023-06-12 18:30:53 -03:00
anovazzi1
72dea88f14 moved validateNodes function to utils 2023-06-12 18:20:52 -03:00
Gabriel Luiz Freitas Almeida
312e0c4834 🐛 fix(GenericNode): set validationStatus to null when relevantData is null
This change fixes a bug where the validationStatus state was not being set to null when relevantData was null. This caused the validationStatus to retain its previous value, which could lead to incorrect validation results being displayed.
2023-06-12 17:05:05 -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
de7b2c9f31 🔥 chore(chatComponent): remove unused imports and API call
The import for the postBuild function was removed as it was not being used in the BuildTrigger component. This improves the code's readability and maintainability.

🚀 feat(chatComponent): add useEffect hook to fetch build status and update state
An async function was added to fetch the build status of the flow and update the state of the isBuilt variable. This allows the component to display the correct state of the build trigger button.

👌 refactor(chatComponent): refactor useEffect hook to update isBuilt state when nodes change
The useEffect hook was refactored to update the isBuilt state when the nodes change. This ensures that the build trigger button is disabled when the nodes change, as the flow needs to be rebuilt before it can be triggered again.

🔥 chore(intComponent): remove console.log statement
The console.log statement was removed from the onKeyDown event listener in the IntComponent component. This improves the code's cleanliness and readability.
2023-06-12 17:04:19 -03:00
Gabriel Luiz Freitas Almeida
d381228b83 🚀 feat(API): add BuildStatusTypeAPI to API types and implement getBuildStatus function
The BuildStatusTypeAPI was added to the API types to support the new getBuildStatus function. The getBuildStatus function retrieves the build status of a flow by making a GET request to the server. This function is useful for updating the UI with the current status of a flow.
2023-06-12 17:03:54 -03:00
Gabriel Luiz Freitas Almeida
68e17384c8 🔧 chore(chatModal): extract getWebSocketUrl function to improve readability and maintainability
The getWebSocketUrl function was extracted to improve the readability and maintainability of the code. It takes the chatId and isDevelopment flag as parameters and returns the WebSocket URL based on the current environment. The function uses the window.location object to determine the protocol and host, and the chatEndpoint to construct the URL.
2023-06-12 17:03:36 -03:00
Gabriel Luiz Freitas Almeida
bc499b285d 🚀 feat(api): add BuildStatusTypeAPI to represent the status of a build
The BuildStatusTypeAPI is added to represent the status of a build. It contains a boolean value indicating whether the build was successful or not.
2023-06-12 17:03:22 -03:00
Gabriel Luiz Freitas Almeida
a7c9b04611 🚨 test(conftest.py): add basic_graph_data fixture to load basic example data
🚨 test(test_websocket.py): add tests for build init, stream, and websocket endpoint
The `basic_graph_data` fixture is added to load the basic example data. The `test_init_build`, `test_stream_build`, and `test_websocket_endpoint` tests are added to test the build init, stream, and websocket endpoint. The `test_websocket_endpoint_after_build` test is added to test the websocket endpoint after the build.
2023-06-12 13:06:39 -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
64397d2830 🔨 refactor(buildTrigger): change allNodesValid to validationResults array and add finished variable to improve readability
🚀 feat(buildTrigger): add waiting for stream to finish and return validation results for each node
The allNodesValid variable has been changed to a validationResults array to store the validation results for each node. A finished variable has been added to improve readability and to wait for the stream to finish. The function now returns an array of validation results for each node.
2023-06-12 13:05:02 -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
bcff7a42eb 🔥 chore(test_websocket.py): remove unused import
The import statement for TestClient is unused and can be safely removed.
2023-06-12 10:44:03 -03:00
Gabriel Luiz Freitas Almeida
5fe1435f9e 🔥 chore(test_websocket.py): remove unused imports
The imports for json and patch were not used in the file and were removed to improve code readability and maintainability.
2023-06-12 09:55:48 -03:00
Gabriel Luiz Freitas Almeida
4485f55d53 🔥 chore(test_websocket.py): remove outdated test_chat_history test
The test_chat_history test is outdated and no longer works with the current implementation of the application. It has been removed to avoid confusion and to keep the test suite clean.
2023-06-12 09:51:32 -03:00
Gabriel Luiz Freitas Almeida
6b57e20504 formatting 2023-06-12 09:45:28 -03:00
Gabriel Luiz Freitas Almeida
4f4a0ff4c7 🔨 refactor(chatComponent): refactor handleBuild function to use async/await and extract constants to improve readability
🐛 fix(chatComponent): fix issue with progressEvent not being properly destructured
🚀 feat(chatComponent): add minimum loading time to improve user experience
The handleBuild function was refactored to use async/await and constants were extracted to improve readability. The issue with progressEvent not being properly destructured was fixed. A minimum loading time was added to improve user experience by ensuring that the loading spinner is displayed for at least a certain amount of time.
2023-06-12 09:44:12 -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
25f22ae88c 🔇 chore(frontend): comment out console.log statements
The console.log statements were commented out in the tabsContext.tsx, EditNodeModal/index.tsx, NodeToolbarComponent/index.tsx, and FlowPage/index.tsx files to remove unnecessary logging in the console.
2023-06-12 09:33:03 -03:00
Gabriel Luiz Freitas Almeida
68288be80e feat (GenericNode): replace validation with SSE validation 2023-06-12 09:31:43 -03:00
Gabriel Luiz Freitas Almeida
eaae1dda27 feat(chatComponent): add SSE context to update data in real-time
The handleBuild function has been refactored to process data in chunks instead of waiting for the entire response to be received. This improves the performance of the function and allows for real-time updates. The SSE context has been added to update the data in real-time as it is received.
🔨 refactor(chatComponent): refactor handleBuild function to process data in chunks
2023-06-12 09:31:01 -03:00
Gabriel Luiz Freitas Almeida
42d5a501bb 🚀 feat(App.tsx): add SSEProvider to App component
🎉 feat(SSEContext.tsx): add SSEContext and SSEProvider components to handle server-sent events
The SSEProvider component was added to the App component to provide the SSEContext to the TabsManagerComponent. The SSEContext component was also added to handle server-sent events. The SSEContext component provides a way to update the sseData state and to access the sseData state from any component that uses the useSSE hook.
2023-06-12 09:30:47 -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
f88b14f33d 🚀 feat(chatComponent): add build trigger component to allow users to build a flow
 feat(chatComponent): add loading animation to build trigger component
The BuildTrigger component is added to the chatComponent to allow users to build a flow. The component is triggered by clicking on a button and sends a POST request to the server to build the flow. A loading animation is added to the component to indicate that the flow is being built. The postBuild function is added to the API controller to handle the POST request.
2023-06-11 18:09:17 -03:00
Gabriel Luiz Freitas Almeida
2c0a9aee95 🚸 chore(chatTrigger): add error message when chat is triggered before flow is built
 feat(chatComponent): add BuildTrigger component to check if flow is built before showing ChatTrigger component
The ChatTrigger component now checks if the flow is built before allowing the user to open the chat. If the flow is not built, an error message is displayed instead. The BuildTrigger component is added to check if the flow is built before showing the ChatTrigger component. This improves the user experience by preventing the user from opening the chat before the flow is built.
2023-06-11 18:08:52 -03:00