feat(toolkits): add @dependencies_required and @api_keys_required decorators to toolkits#4056
Conversation
…orators to toolkits
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@Mubin-A-Kader Thanks for working on the toolkits decorator refactor. There are still a few missing dependency checks in the files changed by this PR:
There are also several other toolkits whose optional dependencies or API keys are not covered in this PR, such as |
Thanks @fengju0213 .. |
Phase 1 — fill gaps flagged in review on PR camel-ai#4056: - excel_toolkit.extract_excel_content: add tabulate, xls2xlsx - google_scholar_toolkit.get_full_paper_content_by_link: add arxiv2text - reddit_toolkit.perform_sentiment_analysis: add textblob Phase 2 — extend to additional toolkits: - weather_toolkit.get_weather_data: pyowm - slack_toolkit.__init__: slack_sdk - open_api_toolkit.parse_openapi_file: prance - gmail_toolkit._authenticate: googleapiclient, google_auth_oauthlib, google.auth, google.oauth2, dotenv - earth_science_toolkit.__init__: numpy, rasterio - earth_science_toolkit scipy methods (6): scipy Skipped JinaRerankerToolkit (dual API/local mode makes a static decorator unsafe). Tests: 11 new cases in test_toolkits_decorators.py plus two helpers (_only_missing for isolated method-level checks, _all_available for bypassing __init__ decorators when optional deps are absent in the test env).
|
Hi @fengju0213 , Updated PR per review feedback.
|
|
Hi @fengju0213 Could you please review this changes |

Closes #1043
Description
Adds
@dependencies_requiredand@api_keys_requireddecorators to toolkits incamel.toolkits. Users now get a clearImportErrororValueErrorimmediately on instantiation or method call instead of a cryptic traceback when required packages or API keys are missing. Follows the same pattern as PR #3992 which did this for embeddings.Changes
SymPyToolkit@dependencies_required('sympy')NetworkXToolkit@dependencies_required('networkx')Crawl4AIToolkit@dependencies_required('crawl4ai')ExcelToolkit@dependencies_required('pandas', 'openpyxl')on__init__;@dependencies_required('tabulate', 'xls2xlsx')onextract_excel_contentGoogleScholarToolkit@dependencies_required('scholarly')on__init__;@dependencies_required('arxiv2text')onget_full_paper_content_by_linkRedditToolkit@dependencies_required('praw')+@api_keys_requiredforREDDIT_CLIENT_ID,REDDIT_CLIENT_SECRET,REDDIT_USER_AGENT;@dependencies_required('textblob')onperform_sentiment_analysisWeatherToolkit@dependencies_required('pyowm')onget_weather_dataSlackToolkit@dependencies_required('slack_sdk')on__init__OpenAPIToolkit@dependencies_required('prance')onparse_openapi_fileGmailToolkit@dependencies_required('googleapiclient', 'google_auth_oauthlib', 'google.auth', 'google.oauth2', 'dotenv')on_authenticateEarthScienceToolkit@dependencies_required('numpy', 'rasterio')on__init__;@dependencies_required('scipy')on 6 scipy-using methodsSkipped:
JinaRerankerToolkit— dual API/local mode makes a static decorator unsafe (API users would be blocked even though local-model deps aren't needed).Added/extended
test/toolkits/test_toolkits_decorators.pywith 19 unit tests total following the same pattern astest/embeddings/test_embeddings_decorators.pyfrom PR #3992. Two helpers (_only_missing,_all_available) isolate method-level decorator checks even when optional deps are absent from the test env.What is the purpose of this pull request?
Checklist
pyproject.toml