-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Conversation
…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.
CodSpeed Performance ReportMerging #4493 will degrade performances by 12.66%Comparing Summary
Benchmarks breakdown
|
There was a problem hiding this 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
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:
ToolException
handling induck_duck_go_search_run.py
,glean_search_api.py
,serp_api.py
,tavily_search.py
, andyahoo_finance.py
to provide more informative error messages and improve error handling. [1] [2] [3] [4] [5]Schema and Input Refactoring:
SerpAPISchema
,TavilySearchSchema
,GleanSearchAPISchema
) to better define input parameters and improve code readability. [1] [2] [3]TavilySearchToolComponent
to use enums forsearch_depth
andtopic
parameters, ensuring valid values and improving code clarity. [1] [2]Method Refactoring:
_build_wrapper
methods inserp_api.py
andglean_search_api.py
to accept parameters and improve flexibility. [1] [2]run_model
methods to include type hints and handle type assignments more gracefully. [1] [2] [3]Miscellaneous Changes:
type: ignore
comments to suppress type checking warnings where necessary. [1] [2] [3]Enum
andToolException
where needed. [1] [2]