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

refactor: Enhance tools with enums and improved error handling #4493

Merged
merged 11 commits into from
Nov 12, 2024

Conversation

ogabrielluiz
Copy link
Contributor

@ogabrielluiz ogabrielluiz commented Nov 11, 2024

This pull request includes several updates to various search tool components in the backend. The main changes involve adding exception handling, updating schema definitions, and refactoring some methods for better code organization and clarity.

Exception Handling Improvements:

  • Added ToolException handling in duck_duck_go_search_run.py, glean_search_api.py, serp_api.py, tavily_search.py, and yahoo_finance.py to provide more informative error messages and improve error handling. [1] [2] [3] [4] [5]

Schema and Input Refactoring:

  • Introduced new schema classes (SerpAPISchema, TavilySearchSchema, GleanSearchAPISchema) to better define input parameters and improve code readability. [1] [2] [3]
  • Updated TavilySearchToolComponent to use enums for search_depth and topic parameters, ensuring valid values and improving code clarity. [1] [2]

Method Refactoring:

  • Refactored _build_wrapper methods in serp_api.py and glean_search_api.py to accept parameters and improve flexibility. [1] [2]
  • Updated run_model methods to include type hints and handle type assignments more gracefully. [1] [2] [3]

Miscellaneous Changes:

  • Added type: ignore comments to suppress type checking warnings where necessary. [1] [2] [3]
  • Included additional imports for Enum and ToolException where needed. [1] [2]

…ce tool

- Introduced YahooFinanceMethod enum to standardize method options.
- Updated YahooFinanceSchema to use the new enum for method selection.
- Enhanced error handling by raising ToolException on data retrieval failure.
- Refactored method handling in _yahoo_finance_tool to use enum values.
- Introduced `TavilySearchDepth` and `TavilySearchTopic` enums for better type safety and clarity.
- Updated `TavilySearchSchema` to use enums for `search_depth` and `topic` fields.
- Added validation for enum values in `run_model` and `_tavily_search` methods.
- Improved error handling by raising `ToolException` for HTTP and unexpected errors.
- Updated dropdown inputs to use enum options directly.
- Introduced `ToolException` for improved error handling in SerpAPI searches.
- Added `SerpAPISchema` for structured search parameters.
- Modified `_build_wrapper` to accept dynamic parameters.
- Enhanced `search_func` to rebuild wrapper with new parameters and handle exceptions.
Refactor the API wrapper and schema for better clarity and maintainability. Improve error handling for search results and streamline request preparation.
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. enhancement New feature or request labels Nov 11, 2024
@github-actions github-actions bot added refactor Maintenance tasks and housekeeping and removed enhancement New feature or request labels Nov 11, 2024
Copy link

codspeed-hq bot commented Nov 11, 2024

CodSpeed Performance Report

Merging #4493 will degrade performances by 12.66%

Comparing improve-tools (71ca5ea) with main (bbaec2b)

Summary

⚡ 1 improvements
❌ 1 regressions
✅ 13 untouched benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark main improve-tools Change
test_successful_run_with_input_type_any 454.8 ms 520.7 ms -12.66%
test_successful_run_with_input_type_text 532.6 ms 457.7 ms +16.37%

@ogabrielluiz ogabrielluiz changed the title refactor: itEnhance tools with enums and improved error handling refactor: Enhance tools with enums and improved error handling Nov 11, 2024
@github-actions github-actions bot added refactor Maintenance tasks and housekeeping and removed refactor Maintenance tasks and housekeeping labels Nov 11, 2024
Base automatically changed from fix-class-eval to main November 11, 2024 13:44
@github-actions github-actions bot added refactor Maintenance tasks and housekeeping and removed refactor Maintenance tasks and housekeeping labels Nov 11, 2024
@github-actions github-actions bot added refactor Maintenance tasks and housekeeping and removed refactor Maintenance tasks and housekeeping labels Nov 11, 2024
Copy link
Collaborator

@erichare erichare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So much cleaner. I tested the Glean Search API one as I was involved in that, works great and i love that the class structure is easier to follow now

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Nov 11, 2024
@ogabrielluiz ogabrielluiz enabled auto-merge (squash) November 11, 2024 22:01
@ogabrielluiz ogabrielluiz merged commit 7dfce1d into main Nov 12, 2024
28 checks passed
@ogabrielluiz ogabrielluiz deleted the improve-tools branch November 12, 2024 11:59
diogocabral pushed a commit to headlinevc/langflow that referenced this pull request Nov 26, 2024
…low-ai#4493)

* fix: Enhance extract_class_name function to identify Component subclasses

* Add TODO for improving Component inheritance check in validate.py

* Add YahooFinanceMethod enum and improve error handling in Yahoo Finance tool

- Introduced YahooFinanceMethod enum to standardize method options.
- Updated YahooFinanceSchema to use the new enum for method selection.
- Enhanced error handling by raising ToolException on data retrieval failure.
- Refactored method handling in _yahoo_finance_tool to use enum values.

* Enhance TavilySearchToolComponent with Enums and Improved Error Handling

- Introduced `TavilySearchDepth` and `TavilySearchTopic` enums for better type safety and clarity.
- Updated `TavilySearchSchema` to use enums for `search_depth` and `topic` fields.
- Added validation for enum values in `run_model` and `_tavily_search` methods.
- Improved error handling by raising `ToolException` for HTTP and unexpected errors.
- Updated dropdown inputs to use enum options directly.

* Add error handling and parameter flexibility to SerpAPI tool

- Introduced `ToolException` for improved error handling in SerpAPI searches.
- Added `SerpAPISchema` for structured search parameters.
- Modified `_build_wrapper` to accept dynamic parameters.
- Enhanced `search_func` to rebuild wrapper with new parameters and handle exceptions.

* feat: Enhance Glean Search API integration

Refactor the API wrapper and schema for better clarity and maintainability. Improve error handling for search results and streamline request preparation.

* Add error handling to DuckDuckGo search function using ToolException

---------

Co-authored-by: Eric Hare <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm This PR has been approved by a maintainer refactor Maintenance tasks and housekeeping size:L This PR changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants