Skip to content

Comments

Dappier tool#1

Closed
amaan-ai20 wants to merge 29 commits intomainfrom
dappier-tool
Closed

Dappier tool#1
amaan-ai20 wants to merge 29 commits intomainfrom
dappier-tool

Conversation

@amaan-ai20
Copy link
Collaborator

@amaan-ai20 amaan-ai20 commented Mar 26, 2025

Description

Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.

Fixes # (issue)

New Package?

Did I fill in the tool.llamahub section in the pyproject.toml and provide a detailed README.md for my new integration or package?

  • Yes
  • No

Version Bump?

Did I bump the version in the pyproject.toml file of the package I am updating? (Except for the llama-index-core package)

  • Yes
  • No

Type of Change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Your pull-request will likely not be merged unless it is covered by some form of impactful unit testing.

  • I added new unit tests to cover this change
  • I believe this change is already covered by existing unit tests

Suggested Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added Google Colab support for the newly added notebooks.
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I ran make format; make lint to appease the lint gods

Summary by CodeRabbit

  • New Features
    • Introduced Dappier integration tools that power AI-driven content recommendations and real-time search capabilities for up-to-date data insights.
  • Documentation
    • Expanded reference materials with a new section for the dappier module, including detailed specifications and usage examples.
    • Added tutorials in Jupyter notebooks for building AI recommendation agents and real-time search agents.
  • Tests
    • Added comprehensive tests to ensure the reliability and performance of the new functionalities.
  • Chores
    • Enhanced project configuration and developer tooling, including licensing updates and build improvements for smoother operations.

@coderabbitai
Copy link

coderabbitai bot commented Mar 26, 2025

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Walkthrough

This pull request adds a new Dappier tools module with two tool specifications—DappierAIRecommendationsToolSpec and DappierRealTimeSearchToolSpec—by documenting them, updating JSON mappings, and providing integration files. It includes new documentation entries, configuration files, build scripts, source code implementations, notebooks for usage tutorials, and tests to validate the new tool functionalities.

Changes

File(s) Change Summary
docs/.../dappier.md, docs/mkdocs.yml Added documentation entry for llama_index.tools.dappier including navigation and plugin configuration.
llama-index-cli/.../mappings.json, llama-index-core/.../mappings.json Added JSON mappings linking DappierAIRecommendationsToolSpec and DappierRealTimeSearchToolSpec to llama_index.tools.dappier.
llama-index-integrations/tools/llama-index-tools-dappier/{.gitignore, BUILD, LICENSE, Makefile, README.md, pyproject.toml} Introduced integration and configuration files including build scripts, license, and readme for the Dappier tools package.
llama-index-integrations/tools/llama-index-tools-dappier/llama_index/tools/dappier/{BUILD, __init__.py}
llama-index-integrations/tools/llama-index-tools-dappier/llama_index/tools/dappier/ai_recommendations/{BUILD, base.py}
llama-index-integrations/tools/llama-index-tools-dappier/llama_index/tools/dappier/real_time_search/{BUILD, base.py}
Added new Python modules and BUILD configurations defining and exporting the two Dappier tool specifications with their respective API interactions.
llama-index-integrations/tools/llama-index-tools-dappier/examples/{dappier_ai_recommendations.ipynb, dappier_real_time_search.ipynb} Provided Jupyter notebooks demonstrating the usage of the Dappier AI recommendations and real-time search functionalities.
llama-index-integrations/tools/llama-index-tools-dappier/tests/{BUILD, test_tools_dappier_ai_recommendations.py, test_tools_dappier_real_time_search.py} Introduced test targets and unit tests to validate the behavior and inheritance of the new Dappier tool specifications.

Sequence Diagram(s)

Dappier AI Recommendations Workflow

sequenceDiagram
    participant User
    participant Agent
    participant DappierClient
    participant DappierAPI
    User->>Agent: Request AI recommendations (e.g., sports news)
    Agent->>DappierClient: get_sports_news_recommendations(query)
    DappierClient->>DappierAPI: Send API request with parameters
    DappierAPI-->>DappierClient: Return recommendation data
    DappierClient-->>Agent: Return formatted recommendations
    Agent-->>User: Deliver recommendations response
Loading

Dappier Real-Time Search Workflow

sequenceDiagram
    participant User
    participant Agent
    participant DappierClient
    participant DappierAPI
    User->>Agent: Request real-time search (e.g., weather update)
    Agent->>DappierClient: search_real_time_data(query)
    DappierClient->>DappierAPI: Send API request with query
    DappierAPI-->>DappierClient: Return search results
    DappierClient-->>Agent: Return formatted search result
    Agent-->>User: Deliver search response
Loading

Possibly related PRs

  • DappierAI/mintlify-docs#27: Introduces actions for fetching real-time data and generating recommendations, closely aligning with the Dappier API functionalities implemented here.
  • DappierAI/mintlify-docs#34: Defines similar dappier_real_time_search and dappier_ai_recommendations functionality, directly related to these new tool specifications.
  • DappierAI/mintlify-docs#3: Enhances the Dappier API request schema for parameters such as query, ref, and search_algorithm, which are utilized by the new specifications.

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro (Legacy)

📥 Commits

Reviewing files that changed from the base of the PR and between 11f7284 and c602738.

📒 Files selected for processing (2)
  • llama-index-integrations/tools/llama-index-tools-dappier/pyproject.toml (1 hunks)
  • llama-index-integrations/tools/llama-index-tools-dappier/tests/test_tools_dappier_ai_recommendations.py (1 hunks)

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 17

🔭 Outside diff range comments (2)
llama-index-integrations/tools/llama-index-tools-dappier/llama_index/tools/dappier/__init__.py (1)

1-12: 🧹 Nitpick (assertive)

Module Initialization and Explicit Exports are Correct
The file correctly imports and re-exports the two Dappier tool specification classes. As this is a new integration module, consider adding a module-level docstring to explain the purpose of the module and its contents, which would aid future maintainability and onboarding.

docs/docs/api_reference/tools/dappier.md (1)

1-6: 🧹 Nitpick (assertive)

Documentation Format Improvement: Add a Top-Level Heading
While the content correctly documents the available members in the llama_index.tools.dappier module, it is recommended to include a top-level heading (for example, # Dappier Tools Module) at the start of the file. This change will improve readability and ensure compliance with markdownlint MD041.

🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

1-1: First line in a file should be a top-level heading
null

(MD041, first-line-heading, first-line-h1)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 53e3439 and 11f7284.

📒 Files selected for processing (21)
  • docs/docs/api_reference/tools/dappier.md (1 hunks)
  • docs/mkdocs.yml (2 hunks)
  • llama-index-cli/llama_index/cli/upgrade/mappings.json (1 hunks)
  • llama-index-core/llama_index/core/command_line/mappings.json (1 hunks)
  • llama-index-integrations/tools/llama-index-tools-dappier/.gitignore (1 hunks)
  • llama-index-integrations/tools/llama-index-tools-dappier/BUILD (1 hunks)
  • llama-index-integrations/tools/llama-index-tools-dappier/LICENSE (1 hunks)
  • llama-index-integrations/tools/llama-index-tools-dappier/Makefile (1 hunks)
  • llama-index-integrations/tools/llama-index-tools-dappier/README.md (1 hunks)
  • llama-index-integrations/tools/llama-index-tools-dappier/examples/dappier_ai_recommendations.ipynb (1 hunks)
  • llama-index-integrations/tools/llama-index-tools-dappier/examples/dappier_real_time_search.ipynb (1 hunks)
  • llama-index-integrations/tools/llama-index-tools-dappier/llama_index/tools/dappier/BUILD (1 hunks)
  • llama-index-integrations/tools/llama-index-tools-dappier/llama_index/tools/dappier/__init__.py (1 hunks)
  • llama-index-integrations/tools/llama-index-tools-dappier/llama_index/tools/dappier/ai_recommendations/BUILD (1 hunks)
  • llama-index-integrations/tools/llama-index-tools-dappier/llama_index/tools/dappier/ai_recommendations/base.py (1 hunks)
  • llama-index-integrations/tools/llama-index-tools-dappier/llama_index/tools/dappier/real_time_search/BUILD (1 hunks)
  • llama-index-integrations/tools/llama-index-tools-dappier/llama_index/tools/dappier/real_time_search/base.py (1 hunks)
  • llama-index-integrations/tools/llama-index-tools-dappier/pyproject.toml (1 hunks)
  • llama-index-integrations/tools/llama-index-tools-dappier/tests/BUILD (1 hunks)
  • llama-index-integrations/tools/llama-index-tools-dappier/tests/test_tools_dappier_ai_recommendations.py (1 hunks)
  • llama-index-integrations/tools/llama-index-tools-dappier/tests/test_tools_dappier_real_time_search.py (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.py`: Be sure that the code is optimized to enable concurrency, efficient use of threading and follows the standard Python guide, always point out all possible unhandled error...

**/*.py: Be sure that the code is optimized to enable concurrency, efficient use of threading and follows the standard Python guide, always point out all possible unhandled error case and suggest code snippets to improve key areas such as:
- Logic
- Security
- Performance
- Data races
- Consistency
- Error handling
- Maintainability
- Modularity
- Complexity
- Optimization
- Best practices: DRY, SOLID, KISS

  • llama-index-integrations/tools/llama-index-tools-dappier/tests/test_tools_dappier_ai_recommendations.py
  • llama-index-integrations/tools/llama-index-tools-dappier/llama_index/tools/dappier/__init__.py
  • llama-index-integrations/tools/llama-index-tools-dappier/tests/test_tools_dappier_real_time_search.py
  • llama-index-integrations/tools/llama-index-tools-dappier/llama_index/tools/dappier/real_time_search/base.py
  • llama-index-integrations/tools/llama-index-tools-dappier/llama_index/tools/dappier/ai_recommendations/base.py
🧬 Code Definitions (3)
llama-index-integrations/tools/llama-index-tools-dappier/tests/test_tools_dappier_ai_recommendations.py (1)
llama-index-integrations/tools/llama-index-tools-dappier/tests/test_tools_dappier_real_time_search.py (1)
  • test_class (8-10)
llama-index-integrations/tools/llama-index-tools-dappier/llama_index/tools/dappier/__init__.py (2)
llama-index-integrations/tools/llama-index-tools-dappier/llama_index/tools/dappier/ai_recommendations/base.py (1)
  • DappierAIRecommendationsToolSpec (9-281)
llama-index-integrations/tools/llama-index-tools-dappier/llama_index/tools/dappier/real_time_search/base.py (1)
  • DappierRealTimeSearchToolSpec (9-65)
llama-index-integrations/tools/llama-index-tools-dappier/tests/test_tools_dappier_real_time_search.py (1)
llama-index-integrations/tools/llama-index-tools-dappier/tests/test_tools_dappier_ai_recommendations.py (1)
  • test_class (5-9)
🪛 markdownlint-cli2 (0.17.2)
docs/docs/api_reference/tools/dappier.md

1-1: First line in a file should be a top-level heading
null

(MD041, first-line-heading, first-line-h1)

🪛 LanguageTool
llama-index-integrations/tools/llama-index-tools-dappier/README.md

[uncategorized] ~15-~15: If this is a compound adjective that modifies the following noun, use a hyphen.
Context: ...TV and 9&10 News. ## Key Features ### Real Time Search Tool - Real-Time Web Search...

(EN_COMPOUND_ADJECTIVE_INTERNAL)


[uncategorized] ~44-~44: “Your” (belonging to you) seems less likely than “you”.
Context: ... your API keys for OpenAI and Dappier. Your can go to [here](https://platform.opena...

(AI_HYDRA_LEO_CP_YOUR_YOU)


[uncategorized] ~59-~59: If this is a compound adjective that modifies the following noun, use a hyphen.
Context: ... = "dappier_api_key" ``` ## Usage ### Real Time Search Tool This tool has a more exten...

(EN_COMPOUND_ADJECTIVE_INTERNAL)


[uncategorized] ~85-~85: Loose punctuation mark.
Context: ...lable in are: - search_real_time_data: A tool that performs a real-time web se...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~86-~86: Loose punctuation mark.
Context: ..., and more. - search_stock_market_data: A tool that fetches real-time stock mar...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~114-~114: Loose punctuation mark.
Context: ...re: - get_sports_news_recommendations: A tool that fetches real-time news, upd...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~116-~116: Loose punctuation mark.
Context: ... - get_lifestyle_news_recommendations: A tool that fetches Real-time updates, ...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~118-~118: Loose punctuation mark.
Context: ...oof. - get_iheartdogs_recommendations: A tool that fetches articles on health,...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~120-~120: Loose punctuation mark.
Context: ....com - get_iheartcats_recommendations: A tool that fetches articles on health,...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~122-~122: Loose punctuation mark.
Context: ...om - get_greenmonster_recommendations: A tool that fetches guides to making co...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~124-~124: Loose punctuation mark.
Context: ... planet. - get_wishtv_recommendations: A tool that fetches politics, breaking ...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~126-~126: Loose punctuation mark.
Context: ... get_nine_and_ten_news_recommendations: A tool that fetches up-to-date local ne...

(UNLIKELY_OPENING_PUNCTUATION)

🪛 Ruff (0.8.2)
llama-index-integrations/tools/llama-index-tools-dappier/tests/test_tools_dappier_real_time_search.py

13-13: Use @pytest.fixture over @pytest.fixture()

Remove parentheses

(PT001)


18-18: Use @pytest.fixture over @pytest.fixture()

Remove parentheses

(PT001)

llama-index-integrations/tools/llama-index-tools-dappier/llama_index/tools/dappier/real_time_search/base.py

15-18: Multi-line docstring summary should start at the second line

Insert line break and indentation after opening quotes

(D213)

🔇 Additional comments (23)
llama-index-integrations/tools/llama-index-tools-dappier/LICENSE (1)

1-22: MIT License File Looks Solid

The LICENSE file correctly includes the full MIT License text. It adheres to standard formatting and clearly lays out the permissions, restrictions, and disclaimers. There's no issue with the content, and it sets a proper legal foundation for the new Dappier tools package.

llama-index-integrations/tools/llama-index-tools-dappier/.gitignore (1)

1-154: Comprehensive .gitignore Implementation

This .gitignore file is very thorough—it covers Python bytecode, build artifacts, environment directories, IDE-specific settings, and several framework-specific files. It ensures that unnecessary files won’t pollute the repository. The organization into sections improves readability and maintainability.

llama-index-integrations/tools/llama-index-tools-dappier/Makefile (1)

1-18: Well-Structured Makefile for Dappier Tools

The Makefile defines useful targets including help, format, lint, test, and watch-docs. The use of pre-commit hooks for formatting and linting, as well as integrating pytest for testing and sphinx-autobuild for documentation, reflects a robust and developer-friendly workflow. Verify that the paths (e.g., docs/, tests/, and $(GIT_ROOT)/llama_index/) are correct within your repository structure, though they look appropriate given the context.

llama-index-integrations/tools/llama-index-tools-dappier/BUILD (1)

1-3: Simple and Correct BUILD File Declaration

This BUILD file adds a minimal poetry_requirements target with the name "poetry". The syntax is correct, and it cleanly introduces the dependency management required for the tool. If a version pin or further configuration is needed later, that can be added as a subsequent improvement.

llama-index-integrations/tools/llama-index-tools-dappier/tests/BUILD (1)

1-2: Clean Test BUILD Target

The new target python_tests() is a concise way to define test execution within the build system for the new Dappier tool functionalities. It’s key to confirm that all relevant new test files (e.g., those covering DappierAIRecommendationsToolSpec and DappierRealTimeSearchToolSpec) reside under the tests directory so they get picked up correctly when this target is invoked.

llama-index-integrations/tools/llama-index-tools-dappier/llama_index/tools/dappier/BUILD (1)

1-1: Looks good!

The python_sources() function is correctly used to identify Python source files in this directory for the build system. This is a standard pattern in Pants/Bazel build systems.

llama-index-integrations/tools/llama-index-tools-dappier/llama_index/tools/dappier/ai_recommendations/BUILD (1)

1-1: Looks good!

The python_sources() function is correctly used to identify Python source files in the AI recommendations subdirectory for the build system. This maintains consistency with the parent directory's BUILD file.

llama-index-integrations/tools/llama-index-tools-dappier/llama_index/tools/dappier/real_time_search/BUILD (1)

1-1: Looks good!

The python_sources() function is correctly used to identify Python source files in the real-time search subdirectory for the build system. This maintains consistency with the other Dappier tool subdirectories.

llama-index-cli/llama_index/cli/upgrade/mappings.json (1)

551-552: New Mapping Entries for Dappier Tools Added
The new entries
  "DappierAIRecommendationsToolSpec": "llama_index.tools.dappier"
  "DappierRealTimeSearchToolSpec": "llama_index.tools.dappier"
are correctly added. This update enables the CLI upgrade tool to recognize and correctly map the new Dappier specifications.

llama-index-core/llama_index/core/command_line/mappings.json (1)

551-553: New Dappier Tool Entries Integrated
The new mapping entries for "DappierAIRecommendationsToolSpec" and "DappierRealTimeSearchToolSpec" under the key "llama_index.tools.dappier" have been properly integrated into the command-line mappings. This inclusion ensures consistency across the project components and facilitates the recognition of the new tools.

docs/mkdocs.yml (2)

1679-1680: New Dappier Tool Documentation Entry Added
A new documentation entry for the Dappier tool has been added here via the reference to ./api_reference/tools/dappier.md. Please verify that the corresponding markdown file exists and that its contents appropriately document the new Dappier functionality.


1912-1913: New Integration Paths for Dappier Tools Introduced
Two new paths have been added:

  • ../llama-index-integrations/tools/llama-index-tools-dappier-ai-recommendations
  • ../llama-index-integrations/tools/llama-index-tools-dappier-real-time-search

These entries will incorporate the Dappier Recommendations and Real-Time Search tool specifications into the documentation site. Please double-check that these directories and their documentation files exist and reflect the intended content.

llama-index-integrations/tools/llama-index-tools-dappier/tests/test_tools_dappier_real_time_search.py (3)

34-44: Test looks good

The test properly verifies that the search_real_time_data method returns the expected response and calls the client with the correct parameters.


45-57: Test looks good

The test properly verifies that the search_stock_market_data method returns the expected response and calls the client with the correct parameters.


58-63: Tests for error handling look good

These tests properly verify the behavior when the client returns None, ensuring that appropriate default messages are returned.

Also applies to: 64-69

llama-index-integrations/tools/llama-index-tools-dappier/pyproject.toml (2)

22-22: Python version inconsistency

There's an inconsistency between the mypy Python version (3.8) and the required Python version (>=3.9). Consider aligning these to ensure type checking matches the targeted Python version.

-python_version = "3.8"
+python_version = "3.9"

Also applies to: 34-34


5-8: Configuration structure looks good

The project configuration is well-structured with appropriate sections for build settings, dependencies, development tools, and package metadata. The dependencies are specified with compatible version constraints which is good practice.

Also applies to: 10-16, 18-22, 24-31, 33-36, 38-54, 55-62, 63-65

llama-index-integrations/tools/llama-index-tools-dappier/examples/dappier_ai_recommendations.ipynb (4)

152-157: Secure API key handling looks good

Using getpass to securely prompt for API keys is a good security practice.


175-178: Secure API key handling looks good

Using getpass for the Dappier API key is a good security practice.


211-220: Tool initialization and exploration looks good

The code properly initializes the Dappier tool and explores available methods.


840-858: Notebook metadata looks good

The notebook metadata is properly structured with appropriate kernelspec and language information.

llama-index-integrations/tools/llama-index-tools-dappier/examples/dappier_real_time_search.ipynb (1)

1-19: Notebook metadata looks good.
This is standard Jupyter notebook metadata with no notable issues.

llama-index-integrations/tools/llama-index-tools-dappier/llama_index/tools/dappier/ai_recommendations/base.py (1)

283-314: Good error-checking approach.
The function checks response.status and gracefully returns a user-friendly message when unsuccessful. This straightforward error handling is a solid start.

Comment on lines +13 to +14
@pytest.fixture()
def dappier_client():
Copy link

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Consider removing parentheses from pytest fixture decorator

The pytest fixture decorator should be used without parentheses when no arguments are needed.

-@pytest.fixture()
+@pytest.fixture
 def dappier_client():
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
@pytest.fixture()
def dappier_client():
@pytest.fixture
def dappier_client():
🧰 Tools
🪛 Ruff (0.8.2)

13-13: Use @pytest.fixture over @pytest.fixture()

Remove parentheses

(PT001)

Comment on lines +18 to +19
@pytest.fixture()
def tool(dappier_client):
Copy link

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Consider removing parentheses from pytest fixture decorator

The pytest fixture decorator should be used without parentheses when no arguments are needed.

-@pytest.fixture()
+@pytest.fixture
 def tool(dappier_client):
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
@pytest.fixture()
def tool(dappier_client):
@pytest.fixture
def tool(dappier_client):
🧰 Tools
🪛 Ruff (0.8.2)

18-18: Use @pytest.fixture over @pytest.fixture()

Remove parentheses

(PT001)

Comment on lines +25 to +33
class TestDappierRealTimeSearchTool:
def test_init_without_api_key_raises_value_error(self, monkeypatch):
monkeypatch.delenv("DAPPIER_API_KEY", raising=False)
dappier_client = MagicMock()
with patch("dappier.Dappier", return_value=dappier_client):
with pytest.raises(ValueError) as excinfo:
DappierRealTimeSearchToolSpec()
assert "API key is required" in str(excinfo.value)

Copy link

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Make API key test more resilient

The test for initialization without an API key relies on the environment state. Consider using a more deterministic approach by mocking the os.environ object directly.

 def test_init_without_api_key_raises_value_error(self, monkeypatch):
-    monkeypatch.delenv("DAPPIER_API_KEY", raising=False)
+    # Mock os.environ to ensure deterministic behavior
+    monkeypatch.setattr("os.environ.get", lambda key, default=None: None if key == "DAPPIER_API_KEY" else default)
     dappier_client = MagicMock()
     with patch("dappier.Dappier", return_value=dappier_client):
         with pytest.raises(ValueError) as excinfo:
             DappierRealTimeSearchToolSpec()
     assert "API key is required" in str(excinfo.value)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
class TestDappierRealTimeSearchTool:
def test_init_without_api_key_raises_value_error(self, monkeypatch):
monkeypatch.delenv("DAPPIER_API_KEY", raising=False)
dappier_client = MagicMock()
with patch("dappier.Dappier", return_value=dappier_client):
with pytest.raises(ValueError) as excinfo:
DappierRealTimeSearchToolSpec()
assert "API key is required" in str(excinfo.value)
class TestDappierRealTimeSearchTool:
def test_init_without_api_key_raises_value_error(self, monkeypatch):
- monkeypatch.delenv("DAPPIER_API_KEY", raising=False)
+ # Mock os.environ to ensure deterministic behavior
+ monkeypatch.setattr("os.environ.get", lambda key, default=None: None if key == "DAPPIER_API_KEY" else default)
dappier_client = MagicMock()
with patch("dappier.Dappier", return_value=dappier_client):
with pytest.raises(ValueError) as excinfo:
DappierRealTimeSearchToolSpec()
assert "API key is required" in str(excinfo.value)

Comment on lines +322 to +352
{
"cell_type": "code",
"execution_count": null,
"id": "a33051ce",
"metadata": {},
"outputs": [],
"source": [
"from llama_index.core.agent import FunctionCallingAgent\n",
"from llama_index.llms.openai import OpenAI\n",
"\n",
"agent = FunctionCallingAgent.from_tools(\n",
" dappier_tool_list,\n",
" llm=OpenAI(model=\"gpt-4o\"),\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5bcaa33f006b4fb9",
"metadata": {},
"outputs": [],
"source": [
"from llama_index.core.agent import FunctionCallingAgent\n",
"from llama_index.llms.openai import OpenAI\n",
"\n",
"agent = FunctionCallingAgent.from_tools(\n",
" dappier_tool_list,\n",
" llm=OpenAI(model=\"gpt-4o\"),\n",
")"
]
Copy link

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Avoid code duplication for agent initialization.
The agent initialization is repeated. Consolidate creation in one place to reduce repetition and simplify updates.

- agent = FunctionCallingAgent.from_tools(
-     dappier_tool_list,
-     llm=OpenAI(model="gpt-4o"),
- )
...
- agent = FunctionCallingAgent.from_tools(
-     dappier_tool_list,
-     llm=OpenAI(model="gpt-4o"),
- )

+ def create_dappier_agent(tools, model="gpt-4o"):
+     return FunctionCallingAgent.from_tools(tools, llm=OpenAI(model=model))

# Then call:
+ agent = create_dappier_agent(dappier_tool_list)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
{
"cell_type": "code",
"execution_count": null,
"id": "a33051ce",
"metadata": {},
"outputs": [],
"source": [
"from llama_index.core.agent import FunctionCallingAgent\n",
"from llama_index.llms.openai import OpenAI\n",
"\n",
"agent = FunctionCallingAgent.from_tools(\n",
" dappier_tool_list,\n",
" llm=OpenAI(model=\"gpt-4o\"),\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5bcaa33f006b4fb9",
"metadata": {},
"outputs": [],
"source": [
"from llama_index.core.agent import FunctionCallingAgent\n",
"from llama_index.llms.openai import OpenAI\n",
"\n",
"agent = FunctionCallingAgent.from_tools(\n",
" dappier_tool_list,\n",
" llm=OpenAI(model=\"gpt-4o\"),\n",
")"
]
{
"cell_type": "code",
"execution_count": null,
"id": "a33051ce",
"metadata": {},
"outputs": [],
"source": [
"from llama_index.core.agent import FunctionCallingAgent\n",
"from llama_index.llms.openai import OpenAI\n",
"\n",
"def create_dappier_agent(tools, model=\"gpt-4o\"):\n",
" return FunctionCallingAgent.from_tools(tools, llm=OpenAI(model=model))\n",
"\n",
"agent = create_dappier_agent(dappier_tool_list)\n"
]
}


## Usage

### Real Time Search Tool
Copy link

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Consistently use hyphenated form “Real-Time.”
For consistency, use “Real-Time Search Tool” if it’s functioning as a compound adjective.

-### Real Time Search Tool
+### Real-Time Search Tool
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
### Real Time Search Tool
### Real-Time Search Tool
🧰 Tools
🪛 LanguageTool

[uncategorized] ~59-~59: If this is a compound adjective that modifies the following noun, use a hyphen.
Context: ... = "dappier_api_key" ``` ## Usage ### Real Time Search Tool This tool has a more exten...

(EN_COMPOUND_ADJECTIVE_INTERNAL)


## Key Features

### Real Time Search Tool
Copy link

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Use a hyphen for compound adjective.
“Real-Time” (with a hyphen) is the conventional form when used as an adjective before the noun “Search Tool.”

-### Real Time Search Tool
+### Real-Time Search Tool
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
### Real Time Search Tool
### Real-Time Search Tool
🧰 Tools
🪛 LanguageTool

[uncategorized] ~15-~15: If this is a compound adjective that modifies the following noun, use a hyphen.
Context: ...TV and 9&10 News. ## Key Features ### Real Time Search Tool - Real-Time Web Search...

(EN_COMPOUND_ADJECTIVE_INTERNAL)

## Setup

You'll need to set up your API keys for OpenAI and Dappier.

Copy link

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Fix grammatical error.
Replace “Your” with “You.”

-Your can go to [here](https://platform.openai.com/settings/organization/api-keys) to get API Key 
+You can go to [here](https://platform.openai.com/settings/organization/api-keys) to get API Key
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
You can go to [here](https://platform.openai.com/settings/organization/api-keys) to get API Key
🧰 Tools
🪛 LanguageTool

[uncategorized] ~44-~44: “Your” (belonging to you) seems less likely than “you”.
Context: ... your API keys for OpenAI and Dappier. Your can go to [here](https://platform.opena...

(AI_HYDRA_LEO_CP_YOUR_YOU)

Comment on lines +9 to +25
class DappierAIRecommendationsToolSpec(BaseToolSpec):
"""
Dappier AI Recommendations tool spec.

Provides AI-powered recommendations across various domains such as Sports News,
Lifestyle News, iHeartDogs, iHeartCats, GreenMonster, WISH-TV and 9 and 10 News.
"""

spec_functions = [
"get_sports_news_recommendations",
"get_lifestyle_news_recommendations",
"get_iheartdogs_recommendations",
"get_iheartcats_recommendations",
"get_greenmonster_recommendations",
"get_wishtv_recommendations",
"get_nine_and_ten_news_recommendations",
]
Copy link

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Consider consolidating similar methods.
All methods differ primarily by their data_model_id, which can be defined in a single shared method or dictionary to reduce duplication.

 def get_recommendations(
     self, 
     domain_key: str,
     query: str,
     similarity_top_k: int = 10,
     ref: Optional[str] = None,
     num_articles_ref: int = 0,
     search_algorithm: Literal["most_recent", "semantic", "most_recent_semantic", "trending"] = "most_recent"
 ):
-    data_model_id = <some ID>
+    domain_map = {
+       "sports": "dm_01j0pb465keqmatq9k83dthx34",
+       "lifestyle": "dm_01j0q82s4bfjmsqkhs3ywm3x6y",
+       ...
+    }
+    data_model_id = domain_map[domain_key]
     response = self.client.get_ai_recommendations(
         query=query,
         data_model_id=data_model_id,
         similarity_top_k=similarity_top_k,
         ref=ref,
         num_articles_ref=num_articles_ref,
         search_algorithm=search_algorithm,
     )
     return format_results(response)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
class DappierAIRecommendationsToolSpec(BaseToolSpec):
"""
Dappier AI Recommendations tool spec.
Provides AI-powered recommendations across various domains such as Sports News,
Lifestyle News, iHeartDogs, iHeartCats, GreenMonster, WISH-TV and 9 and 10 News.
"""
spec_functions = [
"get_sports_news_recommendations",
"get_lifestyle_news_recommendations",
"get_iheartdogs_recommendations",
"get_iheartcats_recommendations",
"get_greenmonster_recommendations",
"get_wishtv_recommendations",
"get_nine_and_ten_news_recommendations",
]
def get_recommendations(
self,
domain_key: str,
query: str,
similarity_top_k: int = 10,
ref: Optional[str] = None,
num_articles_ref: int = 0,
search_algorithm: Literal["most_recent", "semantic", "most_recent_semantic", "trending"] = "most_recent"
):
domain_map = {
"sports": "dm_01j0pb465keqmatq9k83dthx34",
"lifestyle": "dm_01j0q82s4bfjmsqkhs3ywm3x6y",
# Add additional domain mappings as needed.
}
data_model_id = domain_map[domain_key]
response = self.client.get_ai_recommendations(
query=query,
data_model_id=data_model_id,
similarity_top_k=similarity_top_k,
ref=ref,
num_articles_ref=num_articles_ref,
search_algorithm=search_algorithm,
)
return format_results(response)

@amaan-ai20 amaan-ai20 closed this Mar 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant