Skip to content
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

feat: Generic Callback Dialog Input for Custom Component #6236

Merged
merged 85 commits into from
Feb 15, 2025
Merged

Conversation

deon-sanchez
Copy link
Collaborator

@deon-sanchez deon-sanchez commented Feb 10, 2025

This pull request adds callback functionality for dialog inputs, starting with the Astra DB component.

@dosubot dosubot bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Feb 10, 2025
@deon-sanchez deon-sanchez self-assigned this Feb 10, 2025
@deon-sanchez deon-sanchez added the DO NOT MERGE Don't Merge this PR label Feb 10, 2025
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:XS This PR changes 0-9 lines, ignoring generated files. labels Feb 10, 2025
codeflash-ai bot added a commit that referenced this pull request Feb 10, 2025
…` by 316% in PR #6236 (`LFOSS-492`)

Certainly! Here is the optimized version of the `AstraDBVectorStoreComponent` class. The code has been reorganized for efficiency, reducing redundant steps and leveraging faster access patterns.



Key optimizations.
1. Removed the redundant `token` argument when calling `get_database` since the `client` object is already initialized with this token.
2. Simplified the conditional check for `dimension` to directly use `is None` for clarity.
3. Removed unnecessary parameters (`authentication`, `parameters`) when initializing `CollectionVectorServiceOptions` to ensure it is as lightweight as possible.
Copy link
Contributor

codeflash-ai bot commented Feb 10, 2025

⚡️ Codeflash found optimizations for this PR

📄 316% (3.16x) speedup for AstraDBVectorStoreComponent.create_collection_api in src/backend/base/langflow/components/vectorstores/astradb.py

⏱️ Runtime : 850 microseconds 204 microseconds (best of 23 runs)

I created a new dependent PR with the suggested changes. Please review:

If you approve, it will be merged into this PR (branch LFOSS-492).

codeflash-ai bot added a commit that referenced this pull request Feb 10, 2025
…` by 38% in PR #6236 (`LFOSS-492`)

To optimize the given Python program for both runtime and memory usage, we can focus on reducing redundancies and improving the efficiency of function calls.



### Key Optimizations

1. **Reduce Redundant Calls:**
   - Cached the function reference `self.collection_data` to avoid repeated lookups within the list comprehension.
   
2. **Getattr for Optional Attributes:**
   - Used `getattr` with defaults for accessing potentially missing attributes to avoid multiple nested `if` conditions.

3. **Single Pass Collection List Processing:**
   - Condensed `database.list_collections(keyspace=keyspace)` and metadata extraction into a single pass within the list comprehension.

4. **Direct Update of Dictionary Items:**
   - Used `update` method on `build_config["collection_name"]` to directly update the keys with new values, making the code cleaner.

These changes should result in faster execution and less memory overhead while maintaining the exact same functionality and return values as the original program.
Copy link
Contributor

codeflash-ai bot commented Feb 10, 2025

⚡️ Codeflash found optimizations for this PR

📄 38% (0.38x) speedup for AstraDBVectorStoreComponent.reset_collection_list in src/backend/base/langflow/components/vectorstores/astradb.py

⏱️ Runtime : 680 milliseconds 491 milliseconds (best of 5 runs)

I created a new dependent PR with the suggested changes. Please review:

If you approve, it will be merged into this PR (branch LFOSS-492).

@erichare erichare changed the title LFOSS-492 - Generic Callback Dialog Input for Custom Component feat: Generic Callback Dialog Input for Custom Component Feb 10, 2025
@github-actions github-actions bot added the enhancement New feature or request label Feb 10, 2025
@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Feb 10, 2025
@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Feb 10, 2025
codeflash-ai bot added a commit that referenced this pull request Feb 10, 2025
…by 70% in PR #6236 (`LFOSS-492`)

Here is the optimized version of the provided Python program.



### Explanation of Optimizations.

1. **Caching Computed Values**: 
   - Implemented caching for the `api_endpoint` and `keyspace` values by checking if they are already computed and stored. This avoids redundant calculations and improves performance.

2. **Removed Redundant Code**: 
   - Removed the redundant `keyspace` assignment inside the `get_keyspace` method, handling it more efficiently by using caching built into the instance with attribute checks. 

By applying these optimizations, the program now avoids unnecessary computations, leading to quicker execution times.
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Feb 14, 2025
@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Feb 14, 2025
codeflash-ai bot added a commit that referenced this pull request Feb 14, 2025
…786% in PR #6236 (`LFOSS-492`)

To optimize the given function, we can reduce the number of potentially redundant operations and ensure that each step is efficiently processed. The optimized code focuses on caching, reducing repeated lookups, and preparing for more efficient search operations.

Here is the optimized version of the given Python program.



### Changes made.

1. **Caching**: Added `lru_cache` to `get_api_endpoint_static` and `get_database_list_static` methods to avoid repeated calls with the same arguments and speed up subsequent lookups.
2. **In-Memory Operations**: Reduced the repetitive lookup and streamlined the database dictionary creation.
3. **Error Handling**: Improved exception handling and removed unnecessary code repetition for skipped conditions.

With these optimizations, the code performs fewer redundant operations and should run faster under typical usage scenarios.
@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Feb 14, 2025
codeflash-ai bot added a commit that referenced this pull request Feb 14, 2025
…by 1,269% in PR #6236 (`LFOSS-492`)

To optimize the provided code for better performance, we can implement a few strategies.

Below is the refactored code with these performance optimizations.

### Key Changes.
codeflash-ai bot added a commit that referenced this pull request Feb 14, 2025
…by 36% in PR #6236 (`LFOSS-492`)

To optimize the given Python program for better runtime performance, I'll focus on restructuring the code to reduce redundant work and aim for more efficient data access patterns where applicable. While the initial implementation is not inherently slow, there are some improvements that can be made. 

Here's the optimized version of your code.



### Changes and Optimizations.
1. **Database List Fetching**.
   - Saved the result of `self.get_database_list()` to `database_list` to avoid multiple calls and improve readability.
   
2. **Optimized Metadata List Comprehension**.
    - Used specific key extraction within the dictionary comprehension for `options_metadata` to make it clearer and possibly slightly more efficient.

3. **Variable Assignment**.
    - Separated the list of database names and metadata dictionary creation to improve readability and simplify checking conditions on the list of database names.

These changes slightly improve the clarity and performance of the code by reducing redundant operations and making the code more maintainable.
@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Feb 15, 2025
@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Feb 15, 2025
@erichare erichare enabled auto-merge February 15, 2025 02:04
@erichare erichare added this pull request to the merge queue Feb 15, 2025
@langflow-ai langflow-ai deleted a comment from codeflash-ai bot Feb 15, 2025
@langflow-ai langflow-ai deleted a comment from codeflash-ai bot Feb 15, 2025
@langflow-ai langflow-ai deleted a comment from codeflash-ai bot Feb 15, 2025
Merged via the queue into main with commit c902fb9 Feb 15, 2025
36 of 37 checks passed
@erichare erichare deleted the LFOSS-492 branch February 15, 2025 02:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DO NOT MERGE Don't Merge this PR enhancement New feature or request lgtm This PR has been approved by a maintainer size:XXL This PR changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants