File size: 1,107 Bytes
372531f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import importlib.util
import os

VALID_RETRIEVERS = [
    "arxiv",
    "bing",
    "custom",
    "duckduckgo",
    "exa",
    "google",
    "searchapi",
    "searx",
    "semantic_scholar",
    "serpapi",
    "serper",
    "tavily",
    "pubmed_central",
]


def check_pkg(pkg: str) -> None:
    if not importlib.util.find_spec(pkg):
        pkg_kebab = pkg.replace("_", "-")
        raise ImportError(
            f"Unable to import {pkg_kebab}. Please install with "
            f"`pip install -U {pkg_kebab}`"
        )

# Get a list of all retriever names to be used as validators for supported retrievers
def get_all_retriever_names() -> list:
    try:
        current_dir = os.path.dirname(__file__)

        all_items = os.listdir(current_dir)

        # Filter out only the directories, excluding __pycache__
        retrievers = [item for item in all_items if os.path.isdir(os.path.join(current_dir, item))]
    except Exception as e:
        print(f"Error in get_all_retriever_names: {e}")
        retrievers = VALID_RETRIEVERS
    
    return retrievers