-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathexceptions.py
292 lines (207 loc) · 6.39 KB
/
exceptions.py
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
"""PandaAI's custom exceptions.
This module contains the implementation of Custom Exceptions.
"""
from pandasai.constants import PANDABI_SETUP_MESSAGE
class InvalidRequestError(Exception):
"""
Raised when the request is not successful.
Args :
Exception (Exception): InvalidRequestError
"""
class APIKeyNotFoundError(Exception):
"""
Raised when the API key is not defined/declared.
Args:
Exception (Exception): APIKeyNotFoundError
"""
class LLMNotFoundError(Exception):
"""
Raised when the LLM is not provided.
Args:
Exception (Exception): LLMNotFoundError
"""
class NoCodeFoundError(Exception):
"""
Raised when no code is found in the response.
Args:
Exception (Exception): NoCodeFoundError
"""
class NoResultFoundError(Exception):
"""
Raised when no result is found in the response.
Args:
Exception (Exception): NoResultFoundError
"""
class MethodNotImplementedError(Exception):
"""
Raised when a method is not implemented.
Args:
Exception (Exception): MethodNotImplementedError
"""
class UnsupportedModelError(Exception):
"""
Raised when an unsupported model is used.
Args:
model_name (str): The name of the unsupported model.
Exception (Exception): UnsupportedModelError
"""
def __init__(self, model_name):
self.model = model_name
super().__init__(
f"Unsupported model: The model '{model_name}' doesn't exist "
f"or is not supported yet."
)
class MissingModelError(Exception):
"""
Raised when deployment name is not passed to azure as it's a required parameter
Args:
Exception (Exception): MissingModelError
"""
class BadImportError(Exception):
"""
Raised when a library not in the whitelist is imported.
Args:
Exception (Exception): BadImportError
"""
def __init__(self, library_name):
"""
__init__ method of BadImportError Class
Args:
library_name (str): Name of the library that is not in the whitelist.
"""
self.library_name = library_name
super().__init__(
f"Generated code includes import of {library_name} which"
" is not in whitelist."
)
class TemplateFileNotFoundError(FileNotFoundError):
"""
Raised when a template file cannot be found.
"""
def __init__(self, template_path, prompt_name="Unknown"):
"""
__init__ method of TemplateFileNotFoundError Class
Args:
template_path (str): Path for template file.
prompt_name (str): Prompt name. Defaults to "Unknown".
"""
self.template_path = template_path
super().__init__(
f"Unable to find a file with template at '{template_path}' "
f"for '{prompt_name}' prompt."
)
class UnSupportedLogicUnit(Exception):
"""
Raised when unsupported logic unit is added in the pipeline
Args:
Exception (Exception): UnSupportedLogicUnit
"""
class InvalidWorkspacePathError(Exception):
"""
Raised when the environment variable of workspace exist but path is invalid
Args:
Exception (Exception): InvalidWorkspacePathError
"""
class InvalidConfigError(Exception):
"""
Raised when config value is not applicable
Args:
Exception (Exception): InvalidConfigError
"""
class MaliciousQueryError(Exception):
"""
Raise error if malicious query is generated
Args:
Exception (Exception): MaliciousQueryError
"""
class InvalidLLMOutputType(Exception):
"""
Raise error if the output type is invalid
Args:
Exception (Exception): InvalidLLMOutputType
"""
class InvalidOutputValueMismatch(Exception):
"""
Raise error if the output value doesn't match with type
Args:
Exception (Exception): InvalidOutputValueMismatch
"""
class ExecuteSQLQueryNotUsed(Exception):
"""
Raise error if Execute SQL Query is not used
Args:
Exception (Exception): ExecuteSQLQueryNotUsed
"""
class PipelineConcatenationError(Exception):
"""
Raise error if vector store is not found
Args:
Exception (Exception): Concatenating wrong pipelines
"""
class MissingVectorStoreError(Exception):
"""
Raise error if vector store is not found
Args:
Exception (Exception): MissingVectorStoreError
"""
class PandaAIApiKeyError(Exception):
"""
Raise error if api key is not found for remote vectorstore and llm
"""
def __init__(self, message=None):
default_message = "PandaAI API key not found. Please set your API key using PandaAI.set_api_key() or by setting the PANDASAI_API_KEY environment variable."
super().__init__(message or default_message)
class PandaAIApiCallError(Exception):
"""
Raise error if exception in API request fails
Args:
Exception (Exception): PandaAIApiCallError
"""
class PandasConnectorTableNotFound(Exception):
"""
Raise error if exception in API request fails
Args:
Exception (Exception): PandasConnectorTableNotFound
"""
class InvalidTrainJson(Exception):
"""
Raise error if train json is not correct
Args:
Exception (Exception): Invalid train json
"""
class InvalidSchemaJson(Exception):
"""
Raise error if schema json is not correct
Args:
Exception (Exception): Invalid json schema
"""
class LazyLoadError(Exception):
"""Raised when trying to access data that hasn't been loaded in lazy load mode."""
pass
class InvalidDataSourceType(Exception):
"""Raised error with invalid data source provided"""
pass
class MaliciousCodeGenerated(Exception):
"""
Raise error if malicious code is generated
Args:
Exception (Exception): MaliciousCodeGenerated
"""
class DatasetNotFound(Exception):
"""
Raise error if dataset not found
Args:
Exception (Exception): DatasetNotFound
"""
class CodeExecutionError(Exception):
"""
Raise error if code execution fails
Args:
Exception (Exception): CodeExecutionError
"""
class VirtualizationError(Exception):
"""Raised when there is an error with DataFrame virtualization."""
pass
class UnsupportedTransformation(Exception):
"""Raised when a transformation is not supported."""
pass