refac
This commit is contained in:
@@ -571,6 +571,8 @@ def _parse_ssl_env(value: str) -> 'bool | _ssl.SSLContext':
|
|||||||
|
|
||||||
REQUESTS_VERIFY = os.getenv('REQUESTS_VERIFY', 'True').lower() == 'true'
|
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', '')
|
_aiohttp_timeout_raw = os.getenv('AIOHTTP_CLIENT_TIMEOUT', '')
|
||||||
try:
|
try:
|
||||||
AIOHTTP_CLIENT_TIMEOUT = int(_aiohttp_timeout_raw) if _aiohttp_timeout_raw else None
|
AIOHTTP_CLIENT_TIMEOUT = int(_aiohttp_timeout_raw) if _aiohttp_timeout_raw else None
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ from typing import Iterator, List, Literal, Union
|
|||||||
import requests
|
import requests
|
||||||
from langchain_core.document_loaders import BaseLoader
|
from langchain_core.document_loaders import BaseLoader
|
||||||
from langchain_core.documents import Document
|
from langchain_core.documents import Document
|
||||||
|
from open_webui.env import TAVILY_API_BASE_URL
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -48,7 +49,7 @@ class TavilyLoader(BaseLoader):
|
|||||||
self.urls = urls if isinstance(urls, list) else [urls]
|
self.urls = urls if isinstance(urls, list) else [urls]
|
||||||
self.extract_depth = extract_depth
|
self.extract_depth = extract_depth
|
||||||
self.continue_on_failure = continue_on_failure
|
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]:
|
def lazy_load(self) -> Iterator[Document]:
|
||||||
"""Extract and yield documents from the URLs using Tavily Extract API."""
|
"""Extract and yield documents from the URLs using Tavily Extract API."""
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ from __future__ import annotations
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
from open_webui.env import TAVILY_API_BASE_URL
|
||||||
from open_webui.retrieval.web.main import SearchResult, get_filtered_results
|
from open_webui.retrieval.web.main import SearchResult, get_filtered_results
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
@@ -25,7 +26,7 @@ def search_tavily(
|
|||||||
Returns:
|
Returns:
|
||||||
A list of SearchResult objects.
|
A list of SearchResult objects.
|
||||||
"""
|
"""
|
||||||
url = 'https://api.tavily.com/search'
|
url = f'{TAVILY_API_BASE_URL}/search'
|
||||||
headers = {
|
headers = {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'Authorization': f'Bearer {api_key}',
|
'Authorization': f'Bearer {api_key}',
|
||||||
|
|||||||
Reference in New Issue
Block a user