Skip to content

Conversation

@g1331
Copy link
Owner

@g1331 g1331 commented Sep 7, 2025

This PR adds a new AI Chat plugin: Tavily – a search engine purpose-built for AI.

Summary:

  • New plugin: tavily_search implemented in modules/self_contained/ai_chat/plugins/tavily_search.py
  • Config model TavilySearchConfig with fields: api_key (required), search_depth (basic/advanced), max_results, include_answer, include_raw_content
  • Lazy import of tavily-python to avoid hard dependency unless the plugin is enabled
  • Registered the plugin in plugins_registry.py
  • No default enablement; users must provide api_key in data/ai_chat/ai_chat.json

Notes:

  • Dependency not added automatically; recommend installing via uv add tavily-python
  • Syntax check via python -m compileall passed.

Please review. Once merged, I can follow up with docs and tests if desired.


Pull Request opened by Augment Code with guidance from the PR author

…in: tavily_search using tavily-python client (lazy import)\n- Config model: TavilySearchConfig with api_key/search_depth/max_results options\n- Registered in ALL_PLUGINS; default disabled until api_key provided\n- Compile check: passed
Copilot AI review requested due to automatic review settings September 7, 2025 05:20
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds a new Tavily search plugin to the AI Chat module, providing AI-powered web search capabilities. Tavily is a search engine specifically designed for AI applications.

Key changes:

  • Implements a new TavilySearchPlugin with comprehensive configuration options including search depth, result limits, and content inclusion settings
  • Adds lazy loading of the tavily-python dependency to avoid hard requirements
  • Registers the plugin in the central plugins registry for availability in the AI chat system

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
modules/self_contained/ai_chat/plugins/tavily_search.py New plugin implementation with config model, search functionality, and error handling
modules/self_contained/ai_chat/plugins_registry.py Registers the new Tavily search plugin in the system

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.


try:
max_results = int(params.get("max_results", self.config.max_results))
except Exception:
Copy link

Copilot AI Sep 7, 2025

Choose a reason for hiding this comment

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

Using bare Exception is too broad. Consider catching specific exceptions like ValueError or TypeError for the int() conversion to provide more precise error handling.

Suggested change
except Exception:
except (ValueError, TypeError):

Copilot uses AI. Check for mistakes.
# 懒加载 tavily 依赖
try:
from tavily import TavilyClient # type: ignore
except Exception:
Copy link

Copilot AI Sep 7, 2025

Choose a reason for hiding this comment

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

Using bare Exception is too broad. Consider catching ImportError or ModuleNotFoundError specifically since this is handling import failures.

Suggested change
except Exception:
except (ImportError, ModuleNotFoundError):

Copilot uses AI. Check for mistakes.

try:
resp: dict[str, Any] = await asyncio.to_thread(_search)
except Exception as e: # 网络或鉴权错误
Copy link

Copilot AI Sep 7, 2025

Choose a reason for hiding this comment

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

Using bare Exception is too broad. Consider catching specific exceptions that the Tavily client might raise, such as authentication errors, network timeouts, or API-specific exceptions to provide more targeted error messages.

Copilot uses AI. Check for mistakes.
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.

2 participants