From 98ee2bdfd3e90faec6bfe8e7ebf5803159f379e3 Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Mon, 24 Aug 2026 17:56:11 -0400 Subject: [PATCH] refac --- backend/open_webui/env.py | 2 ++ backend/open_webui/retrieval/loaders/tavily.py | 3 ++- backend/open_webui/retrieval/web/tavily.py | 3 ++- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/backend/open_webui/env.py b/backend/open_webui/env.py index 17e27b25ac..2d610a3388 100644 --- a/backend/open_webui/env.py +++ b/backend/open_webui/env.py @@ -571,6 +571,8 @@ def _parse_ssl_env(value: str) -> 'bool | _ssl.SSLContext': REQUESTS_VERIFY = os.getenv('REQUESTS_VERIFY', 'True').lower() == 'true' +TAVILY_API_BASE_URL = os.getenv('TAVILY_API_BASE_URL', 'https://api.tavily.com').rstrip('/') + _aiohttp_timeout_raw = os.getenv('AIOHTTP_CLIENT_TIMEOUT', '') try: AIOHTTP_CLIENT_TIMEOUT = int(_aiohttp_timeout_raw) if _aiohttp_timeout_raw else None diff --git a/backend/open_webui/retrieval/loaders/tavily.py b/backend/open_webui/retrieval/loaders/tavily.py index bdf70830e4..39c39f91fb 100644 --- a/backend/open_webui/retrieval/loaders/tavily.py +++ b/backend/open_webui/retrieval/loaders/tavily.py @@ -4,6 +4,7 @@ from typing import Iterator, List, Literal, Union import requests from langchain_core.document_loaders import BaseLoader from langchain_core.documents import Document +from open_webui.env import TAVILY_API_BASE_URL log = logging.getLogger(__name__) @@ -48,7 +49,7 @@ class TavilyLoader(BaseLoader): self.urls = urls if isinstance(urls, list) else [urls] self.extract_depth = extract_depth self.continue_on_failure = continue_on_failure - self.api_url = 'https://api.tavily.com/extract' + self.api_url = f'{TAVILY_API_BASE_URL}/extract' def lazy_load(self) -> Iterator[Document]: """Extract and yield documents from the URLs using Tavily Extract API.""" diff --git a/backend/open_webui/retrieval/web/tavily.py b/backend/open_webui/retrieval/web/tavily.py index 419bebb05e..73cf73152e 100644 --- a/backend/open_webui/retrieval/web/tavily.py +++ b/backend/open_webui/retrieval/web/tavily.py @@ -3,6 +3,7 @@ from __future__ import annotations import logging import requests +from open_webui.env import TAVILY_API_BASE_URL from open_webui.retrieval.web.main import SearchResult, get_filtered_results log = logging.getLogger(__name__) @@ -25,7 +26,7 @@ def search_tavily( Returns: A list of SearchResult objects. """ - url = 'https://api.tavily.com/search' + url = f'{TAVILY_API_BASE_URL}/search' headers = { 'Content-Type': 'application/json', 'Authorization': f'Bearer {api_key}',