searxng.py 1.1 KB

12345678910111213141516171819202122232425262728293031
  1. from typing import Any
  2. from core.tools.entities.values import ToolLabelEnum
  3. from core.tools.errors import ToolProviderCredentialValidationError
  4. from core.tools.provider.builtin.searxng.tools.searxng_search import SearXNGSearchTool
  5. from core.tools.provider.builtin_tool_provider import BuiltinToolProviderController
  6. class SearXNGProvider(BuiltinToolProviderController):
  7. def _validate_credentials(self, credentials: dict[str, Any]) -> None:
  8. try:
  9. SearXNGSearchTool().fork_tool_runtime(
  10. runtime={
  11. "credentials": credentials,
  12. }
  13. ).invoke(
  14. user_id='',
  15. tool_parameters={
  16. "query": "SearXNG",
  17. "limit": 1,
  18. "search_type": "page",
  19. "result_type": "link"
  20. },
  21. )
  22. except Exception as e:
  23. raise ToolProviderCredentialValidationError(str(e))
  24. def _get_tool_labels(self) -> list[ToolLabelEnum]:
  25. return [
  26. ToolLabelEnum.SEARCH, ToolLabelEnum.PRODUCTIVITY
  27. ]