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

Added Tavily search functionality #80

Closed

Conversation

0xtechnoir
Copy link
Collaborator

@0xtechnoir 0xtechnoir commented Jan 31, 2025

Adds a web_searcher IOHandler and a new scraper class. Allows example-api to search the web using Tavily API.

Bit messy right now, as I've left in the debugging console statements.

Summary by CodeRabbit

Release Notes

  • New Features

    • Added web search functionality using Tavily API
    • Introduced API integration capabilities for GitHub and universal API calls
    • Enhanced debugging and logging across the system
  • Dependencies

    • Added @tavily/core library for web scraping support
  • Configuration

    • Added new environment variable for Tavily API Key
  • Documentation

    • Updated example API documentation to reflect new capabilities

The release focuses on expanding API interaction and web search capabilities, with improved logging and error handling across the platform.

@0xtechnoir 0xtechnoir linked an issue Jan 31, 2025 that may be closed by this pull request
Copy link

vercel bot commented Jan 31, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
daydreams ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 31, 2025 10:45am

Copy link
Contributor

coderabbitai bot commented Jan 31, 2025

Walkthrough

This pull request introduces web scraping capabilities to the system by adding support for the Tavily API. The changes include adding a new environment variable for the Tavily API Key, creating a WebSearcher class for web searching functionality, updating the example API demonstration, and adding necessary dependencies. The modifications span across configuration files, core utilities, and example implementations to integrate web search capabilities into the existing system.

Changes

File Change Summary
.env.example Added TAVILY_API_KEY= environment variable
packages/core/package.json Added "@tavily/core": "^0.0.2" dependency
packages/core/src/core/env.ts Added TAVILY_API_KEY: z.string() to environment schema
packages/core/src/core/io/scraper.ts New file implementing WebSearcher class with web scraping functionality
examples/example-api.ts Refactored from Twitter bot to API assistant with new web search capabilities
packages/core/src/core/orchestrator.ts Added debug logging statements
packages/core/src/core/processors/master-processor.ts Updated action and task guidelines
packages/core/src/core/utils.ts Enhanced debug logging for LLM response validation

Sequence Diagram

sequenceDiagram
    participant User
    participant Orchestrator
    participant WebSearcher
    participant TavilyAPI

    User->>Orchestrator: Sends search query
    Orchestrator->>WebSearcher: Invoke web search
    WebSearcher->>TavilyAPI: Request web search
    TavilyAPI-->>WebSearcher: Return search results
    WebSearcher->>Orchestrator: Process and return results
    Orchestrator->>User: Provide search results
Loading

Possibly related PRs

Poem

🐰 A rabbit's web search tale unfolds,
Tavily's magic, our code now holds
Scraping secrets from the net so wide
With API keys and logic applied
Knowledge flows, our system grows bright! 🌐

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 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 generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @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
Contributor

@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: 1

🧹 Nitpick comments (4)
examples/example-api.ts (3)

109-149: Consider reducing verbose debug output or gating logs behind a log level.
While the debug logs are helpful for development, consider either removing them in production or routing them through a logging framework. Also, ensure process.env.TAVILY_API_KEY! is safely validated (the env schema helps, but handle any edge cases gracefully).

- console.log("DEBUG: Full web_searcher context:", {
-     payload,
-     type: typeof payload,
-     keys: payload ? Object.keys(payload) : "no keys",
- });
+ this.logger.debug("web_searcher context", {
+     payload,
+     type: typeof payload,
+     keys: payload ? Object.keys(payload) : "no keys",
+ });

237-240: Replace development logs with a structured logging approach or remove them.
These “DEBUG” logs may clutter production logs, so consider gating them behind log-level checks.


283-284: Use consistent debug logging strategy.
As with other debug statements, unify or remove for clarity.

packages/core/src/core/io/scraper.ts (1)

1-123: Overall implementation is good; consider removing unused function and parameterizing maxResults.

  1. cleanContent method is declared but not referenced. If it’s no longer needed, remove it.
  2. maxResults: 5 is hard-coded. Exposing it as a parameter could enhance flexibility.
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 300eb0a and 7ceefaf.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (8)
  • .env.example (1 hunks)
  • examples/example-api.ts (7 hunks)
  • packages/core/package.json (1 hunks)
  • packages/core/src/core/env.ts (1 hunks)
  • packages/core/src/core/io/scraper.ts (1 hunks)
  • packages/core/src/core/orchestrator.ts (8 hunks)
  • packages/core/src/core/processors/master-processor.ts (2 hunks)
  • packages/core/src/core/utils.ts (2 hunks)
🔇 Additional comments (15)
examples/example-api.ts (5)

2-9: Documentation changes look good.
Thanks for clarifying the focus of this example.


27-30: Imports for WebSearcher and searchedContentSchema look fine.
These additions properly align with the new Tavily API integration.


35-35: ChromaVectorDB name updated to "api_agent".
This change looks consistent with the new context.


304-307: Intro messages look good.
They clearly inform users about the available features.


317-321: Graceful removal of IO handlers is appropriate.
Shutdown logic appears coherent and properly finalizes your orchestrator state.

packages/core/src/core/env.ts (1)

18-18: New required TAVILY_API_KEY environment variable is properly declared.
This ensures the key is always present at runtime.

packages/core/src/core/processors/master-processor.ts (2)

99-101: LGTM! Clear guidelines for web search handling.

The separation between immediate and scheduled web searches using suggestedOutputs and updateTasks respectively provides a clear pattern for handling different search scenarios.


115-118: LGTM! Improved output suggestion flow.

The modified flow that prioritizes user feedback before action handlers will provide better user experience and more responsive interactions.

packages/core/src/core/utils.ts (4)

178-186: LGTM! Enhanced debug logging for raw LLM responses.

Added logging of raw responses will help in debugging LLM parsing issues.


191-198: LGTM! Added successful parse logging.

Logging successful JSON parsing provides better visibility into the processing flow.


206-216: LGTM! Improved error context in parse failures.

Enhanced error logging with position and surrounding context will make debugging parse failures much easier.


231-231: LGTM! Added schema logging for validation failures.

Including the schema in validation error logs will help identify schema mismatches.

packages/core/src/core/orchestrator.ts (1)

450-450: LGTM! Added fallback data for action dispatch.

The addition of fallback data { query: processed.content } when output.data is not provided ensures the action handler always receives valid input.

.env.example (1)

30-31: LGTM! Well-documented environment variable.

The addition of TAVILY_API_KEY with a clear comment and URL reference follows good documentation practices.

packages/core/package.json (1)

37-37: Verify stability of @tavily/core package.

The package version (0.0.2) is very early in development which could indicate an unstable API, potential breaking changes, and limited production readiness.

Let's check the package's current state:

Consider:

  1. Monitoring for updates and breaking changes
  2. Testing thoroughly before deploying to production
  3. Having a rollback plan in case of API instability
✅ Verification successful

Early version (0.0.2) is an official beta release.

This is the official Tavily JavaScript SDK, currently in beta. While breaking changes are possible, the package is actively maintained with comprehensive documentation and support channels available at [email protected].

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify @tavily/core package status

# Check latest version and release frequency
echo "Latest version and publish dates:"
npm view @tavily/core time --json | jq

# Check download statistics for popularity/adoption
echo -e "\nDownload statistics:"
npm view @tavily/core downloads --json | jq

# Check for open issues and PRs to assess maintenance
echo -e "\nGitHub activity:"
gh api -X GET search/repositories\?q\=repo:tavily/core | jq '.items[0] | {stars: .stargazers_count, forks: .forks_count, open_issues: .open_issues_count}'

Length of output: 683


Script:

#!/bin/bash
# Description: Get more package details and verify official status

# Get package metadata
echo "Package details:"
npm view @tavily/core --json | jq '{
  description,
  homepage,
  repository,
  license,
  author,
  maintainers
}'

# Check documentation
echo -e "\nREADME content:"
npm view @tavily/core readme

Length of output: 5651

@@ -282,6 +282,8 @@ export class Orchestrator {
queue.push({ data: initialData, source: sourceName });
}

console.log("DEBUG: Queue ============= : ", queue);
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Replace console.log with logger.debug.

Multiple console.log statements have been added for debugging. These should use the existing logger.debug for consistency and better control over log levels.

Apply this pattern for all debug logs:

-console.log("DEBUG: Queue ============= : ", queue);
+this.logger.debug("Orchestrator.runAutonomousFlow", "Processing queue", { queue });

Also applies to: 358-361, 397-397, 413-413, 439-446, 514-514, 537-537, 614-617

@0xtechnoir 0xtechnoir marked this pull request as draft January 31, 2025 11:51
@0xtechnoir 0xtechnoir self-assigned this Jan 31, 2025
@ponderingdemocritus ponderingdemocritus marked this pull request as ready for review February 1, 2025 23:19
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.

[feat] Scraper functions 50000 $DREAMS
2 participants