forked from Filimoa/open-parse
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path__init__.py
More file actions
96 lines (74 loc) · 2.36 KB
/
__init__.py
File metadata and controls
96 lines (74 loc) · 2.36 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
"""
This is meant to provide a simple wrapper around llama_index's embeddings classes.
"""
from typing import Dict, Type
from llama_index.core.embeddings import BaseEmbedding
class ImportErrorProxy:
"""
Used to raise an ImportError when an attribute or method is accessed on a class that failed to import.
"""
def __init__(self, class_name, install_command):
self.class_name = class_name
self.install_command = install_command
self.error_message = (
f"Missing optional dependency for '{class_name}'. "
f"Please install it by running: '{install_command}'."
)
def __getattr__(self, name):
raise ImportError(
f"{self.error_message} The attribute '{name}' cannot be used."
)
def __call__(self, *args, **kwargs):
raise ImportError(self.error_message)
try:
from llama_index.embeddings.openai import (
OpenAIEmbedding,
)
except ImportError:
OpenAIEmbedding = ImportErrorProxy(
"OpenAIEmbedding",
"pip install openparse[embeddings-openai]",
)
try:
from llama_index.embeddings.azure_openai import (
AzureOpenAIEmbedding,
)
except ImportError:
AzureOpenAIEmbedding = ImportErrorProxy(
"AzureOpenAIEmbedding",
"pip install openparse[embeddings-azure-openai]",
)
try:
from llama_index.embeddings.huggingface import (
HuggingFaceInferenceAPIEmbedding,
)
except ImportError:
HuggingFaceInferenceAPIEmbedding = ImportErrorProxy(
"HuggingFaceInferenceAPIEmbedding",
"pip install openparse[embeddings-huggingface]",
)
try:
from llama_index.embeddings.huggingface_optimum import (
OptimumEmbedding,
)
except ImportError:
OptimumEmbedding = ImportErrorProxy(
"OptimumEmbedding",
"pip install openparse[embeddings-huggingface-optimum]",
)
try:
from llama_index.embeddings.cohere import CohereEmbedding
except ImportError:
CohereEmbedding = ImportErrorProxy(
"CohereEmbedding",
"pip install openparse[embeddings-cohere]",
)
try:
from llama_index.embeddings.text_embeddings_inference import (
TextEmbeddingsInference,
)
except ImportError:
TextEmbeddingsInference = ImportErrorProxy(
"TextEmbeddingsInference",
"pip install openparse[embeddings-text-embeddings-inference]",
)