admin-api-lib 3.2.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. admin_api_lib/__init__.py +0 -0
  2. admin_api_lib/api_endpoints/document_deleter.py +24 -0
  3. admin_api_lib/api_endpoints/document_reference_retriever.py +25 -0
  4. admin_api_lib/api_endpoints/documents_status_retriever.py +20 -0
  5. admin_api_lib/api_endpoints/file_uploader.py +31 -0
  6. admin_api_lib/api_endpoints/source_uploader.py +40 -0
  7. admin_api_lib/api_endpoints/uploader_base.py +30 -0
  8. admin_api_lib/apis/__init__.py +0 -0
  9. admin_api_lib/apis/admin_api.py +197 -0
  10. admin_api_lib/apis/admin_api_base.py +120 -0
  11. admin_api_lib/chunker/__init__.py +0 -0
  12. admin_api_lib/chunker/chunker.py +25 -0
  13. admin_api_lib/dependency_container.py +236 -0
  14. admin_api_lib/extractor_api_client/__init__.py +0 -0
  15. admin_api_lib/extractor_api_client/openapi_client/__init__.py +38 -0
  16. admin_api_lib/extractor_api_client/openapi_client/api/__init__.py +4 -0
  17. admin_api_lib/extractor_api_client/openapi_client/api/extractor_api.py +516 -0
  18. admin_api_lib/extractor_api_client/openapi_client/api_client.py +695 -0
  19. admin_api_lib/extractor_api_client/openapi_client/api_response.py +20 -0
  20. admin_api_lib/extractor_api_client/openapi_client/configuration.py +460 -0
  21. admin_api_lib/extractor_api_client/openapi_client/exceptions.py +197 -0
  22. admin_api_lib/extractor_api_client/openapi_client/models/__init__.py +21 -0
  23. admin_api_lib/extractor_api_client/openapi_client/models/content_type.py +34 -0
  24. admin_api_lib/extractor_api_client/openapi_client/models/extraction_parameters.py +103 -0
  25. admin_api_lib/extractor_api_client/openapi_client/models/extraction_request.py +82 -0
  26. admin_api_lib/extractor_api_client/openapi_client/models/information_piece.py +104 -0
  27. admin_api_lib/extractor_api_client/openapi_client/models/key_value_pair.py +92 -0
  28. admin_api_lib/extractor_api_client/openapi_client/rest.py +209 -0
  29. admin_api_lib/extractor_api_client/openapi_client/test/__init__.py +0 -0
  30. admin_api_lib/extractor_api_client/openapi_client/test/test_content_type.py +35 -0
  31. admin_api_lib/extractor_api_client/openapi_client/test/test_extraction_parameters.py +59 -0
  32. admin_api_lib/extractor_api_client/openapi_client/test/test_extraction_request.py +56 -0
  33. admin_api_lib/extractor_api_client/openapi_client/test/test_extractor_api.py +39 -0
  34. admin_api_lib/extractor_api_client/openapi_client/test/test_information_piece.py +62 -0
  35. admin_api_lib/extractor_api_client/openapi_client/test/test_key_value_pair.py +54 -0
  36. admin_api_lib/file_services/file_service.py +77 -0
  37. admin_api_lib/impl/__init__.py +0 -0
  38. admin_api_lib/impl/admin_api.py +167 -0
  39. admin_api_lib/impl/api_endpoints/default_document_deleter.py +84 -0
  40. admin_api_lib/impl/api_endpoints/default_document_reference_retriever.py +72 -0
  41. admin_api_lib/impl/api_endpoints/default_documents_status_retriever.py +41 -0
  42. admin_api_lib/impl/api_endpoints/default_file_uploader.py +234 -0
  43. admin_api_lib/impl/api_endpoints/default_source_uploader.py +202 -0
  44. admin_api_lib/impl/chunker/__init__.py +0 -0
  45. admin_api_lib/impl/chunker/chunker_type.py +11 -0
  46. admin_api_lib/impl/chunker/semantic_text_chunker.py +252 -0
  47. admin_api_lib/impl/chunker/text_chunker.py +33 -0
  48. admin_api_lib/impl/file_services/__init__.py +0 -0
  49. admin_api_lib/impl/file_services/s3_service.py +130 -0
  50. admin_api_lib/impl/information_enhancer/__init__.py +0 -0
  51. admin_api_lib/impl/information_enhancer/general_enhancer.py +52 -0
  52. admin_api_lib/impl/information_enhancer/page_summary_enhancer.py +62 -0
  53. admin_api_lib/impl/information_enhancer/summary_enhancer.py +74 -0
  54. admin_api_lib/impl/key_db/__init__.py +0 -0
  55. admin_api_lib/impl/key_db/file_status_key_value_store.py +111 -0
  56. admin_api_lib/impl/mapper/informationpiece2document.py +108 -0
  57. admin_api_lib/impl/settings/__init__.py +0 -0
  58. admin_api_lib/impl/settings/chunker_class_type_settings.py +18 -0
  59. admin_api_lib/impl/settings/chunker_settings.py +29 -0
  60. admin_api_lib/impl/settings/document_extractor_settings.py +21 -0
  61. admin_api_lib/impl/settings/key_value_settings.py +26 -0
  62. admin_api_lib/impl/settings/rag_api_settings.py +21 -0
  63. admin_api_lib/impl/settings/s3_settings.py +31 -0
  64. admin_api_lib/impl/settings/source_uploader_settings.py +23 -0
  65. admin_api_lib/impl/settings/summarizer_settings.py +86 -0
  66. admin_api_lib/impl/summarizer/__init__.py +0 -0
  67. admin_api_lib/impl/summarizer/langchain_summarizer.py +117 -0
  68. admin_api_lib/information_enhancer/__init__.py +0 -0
  69. admin_api_lib/information_enhancer/information_enhancer.py +34 -0
  70. admin_api_lib/main.py +54 -0
  71. admin_api_lib/models/__init__.py +0 -0
  72. admin_api_lib/models/document_status.py +86 -0
  73. admin_api_lib/models/extra_models.py +9 -0
  74. admin_api_lib/models/http_validation_error.py +105 -0
  75. admin_api_lib/models/key_value_pair.py +85 -0
  76. admin_api_lib/models/status.py +44 -0
  77. admin_api_lib/models/validation_error.py +104 -0
  78. admin_api_lib/models/validation_error_loc_inner.py +114 -0
  79. admin_api_lib/prompt_templates/__init__.py +0 -0
  80. admin_api_lib/prompt_templates/summarize_prompt.py +14 -0
  81. admin_api_lib/rag_backend_client/__init__.py +0 -0
  82. admin_api_lib/rag_backend_client/openapi_client/__init__.py +60 -0
  83. admin_api_lib/rag_backend_client/openapi_client/api/__init__.py +4 -0
  84. admin_api_lib/rag_backend_client/openapi_client/api/rag_api.py +968 -0
  85. admin_api_lib/rag_backend_client/openapi_client/api_client.py +698 -0
  86. admin_api_lib/rag_backend_client/openapi_client/api_response.py +22 -0
  87. admin_api_lib/rag_backend_client/openapi_client/configuration.py +460 -0
  88. admin_api_lib/rag_backend_client/openapi_client/exceptions.py +197 -0
  89. admin_api_lib/rag_backend_client/openapi_client/models/__init__.py +41 -0
  90. admin_api_lib/rag_backend_client/openapi_client/models/chat_history.py +99 -0
  91. admin_api_lib/rag_backend_client/openapi_client/models/chat_history_message.py +83 -0
  92. admin_api_lib/rag_backend_client/openapi_client/models/chat_request.py +93 -0
  93. admin_api_lib/rag_backend_client/openapi_client/models/chat_response.py +103 -0
  94. admin_api_lib/rag_backend_client/openapi_client/models/chat_role.py +35 -0
  95. admin_api_lib/rag_backend_client/openapi_client/models/content_type.py +37 -0
  96. admin_api_lib/rag_backend_client/openapi_client/models/delete_request.py +99 -0
  97. admin_api_lib/rag_backend_client/openapi_client/models/information_piece.py +110 -0
  98. admin_api_lib/rag_backend_client/openapi_client/models/key_value_pair.py +83 -0
  99. admin_api_lib/rag_backend_client/openapi_client/rest.py +209 -0
  100. admin_api_lib/summarizer/__init__.py +0 -0
  101. admin_api_lib/summarizer/summarizer.py +33 -0
  102. admin_api_lib/utils/__init__.py +0 -0
  103. admin_api_lib/utils/utils.py +32 -0
  104. admin_api_lib-3.2.0.dist-info/METADATA +24 -0
  105. admin_api_lib-3.2.0.dist-info/RECORD +106 -0
  106. admin_api_lib-3.2.0.dist-info/WHEEL +4 -0
@@ -0,0 +1,22 @@
1
+ """API response object."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Generic, Mapping, Optional, TypeVar
6
+
7
+ from pydantic import BaseModel, Field, StrictBytes, StrictInt
8
+
9
+ T = TypeVar("T")
10
+
11
+
12
+ class ApiResponse(BaseModel, Generic[T]):
13
+ """
14
+ API response object
15
+ """
16
+
17
+ status_code: StrictInt = Field(description="HTTP status code")
18
+ headers: Optional[Mapping[str, str]] = Field(None, description="HTTP headers")
19
+ data: T = Field(description="Deserialized data given the data type")
20
+ raw_data: StrictBytes = Field(description="Raw data (HTTP response body)")
21
+
22
+ model_config = {"arbitrary_types_allowed": True}
@@ -0,0 +1,460 @@
1
+ # coding: utf-8
2
+
3
+ """
4
+ STACKIT RAG
5
+
6
+ The perfect rag solution.
7
+
8
+ The version of the OpenAPI document: 1.0.0
9
+ Generated by OpenAPI Generator (https://openapi-generator.tech)
10
+
11
+ Do not edit the class manually.
12
+ """ # noqa: E501
13
+
14
+
15
+ import copy
16
+ import http.client as httplib
17
+ import logging
18
+ import multiprocessing
19
+ import sys
20
+ from logging import FileHandler
21
+ from typing import Optional
22
+
23
+ import urllib3
24
+
25
+ JSON_SCHEMA_VALIDATION_KEYWORDS = {
26
+ "multipleOf",
27
+ "maximum",
28
+ "exclusiveMaximum",
29
+ "minimum",
30
+ "exclusiveMinimum",
31
+ "maxLength",
32
+ "minLength",
33
+ "pattern",
34
+ "maxItems",
35
+ "minItems",
36
+ }
37
+
38
+
39
+ class Configuration:
40
+ """This class contains various settings of the API client.
41
+
42
+ :param host: Base url.
43
+ :param ignore_operation_servers
44
+ Boolean to ignore operation servers for the API client.
45
+ Config will use `host` as the base url regardless of the operation servers.
46
+ :param api_key: Dict to store API key(s).
47
+ Each entry in the dict specifies an API key.
48
+ The dict key is the name of the security scheme in the OAS specification.
49
+ The dict value is the API key secret.
50
+ :param api_key_prefix: Dict to store API prefix (e.g. Bearer).
51
+ The dict key is the name of the security scheme in the OAS specification.
52
+ The dict value is an API key prefix when generating the auth data.
53
+ :param username: Username for HTTP basic authentication.
54
+ :param password: Password for HTTP basic authentication.
55
+ :param access_token: Access token.
56
+ :param server_index: Index to servers configuration.
57
+ :param server_variables: Mapping with string values to replace variables in
58
+ templated server configuration. The validation of enums is performed for
59
+ variables with defined enum values before.
60
+ :param server_operation_index: Mapping from operation ID to an index to server
61
+ configuration.
62
+ :param server_operation_variables: Mapping from operation ID to a mapping with
63
+ string values to replace variables in templated server configuration.
64
+ The validation of enums is performed for variables with defined enum
65
+ values before.
66
+ :param ssl_ca_cert: str - the path to a file of concatenated CA certificates
67
+ in PEM format.
68
+ :param retries: Number of retries for API requests.
69
+
70
+ """
71
+
72
+ _default = None
73
+
74
+ def __init__(
75
+ self,
76
+ host=None,
77
+ api_key=None,
78
+ api_key_prefix=None,
79
+ username=None,
80
+ password=None,
81
+ access_token=None,
82
+ server_index=None,
83
+ server_variables=None,
84
+ server_operation_index=None,
85
+ server_operation_variables=None,
86
+ ignore_operation_servers=False,
87
+ ssl_ca_cert=None,
88
+ retries=None,
89
+ *,
90
+ debug: Optional[bool] = None
91
+ ) -> None:
92
+ """Constructor"""
93
+ self._base_path = "http://localhost" if host is None else host
94
+ """Default Base url
95
+ """
96
+ self.server_index = 0 if server_index is None and host is None else server_index
97
+ self.server_operation_index = server_operation_index or {}
98
+ """Default server index
99
+ """
100
+ self.server_variables = server_variables or {}
101
+ self.server_operation_variables = server_operation_variables or {}
102
+ """Default server variables
103
+ """
104
+ self.ignore_operation_servers = ignore_operation_servers
105
+ """Ignore operation servers
106
+ """
107
+ self.temp_folder_path = None
108
+ """Temp file folder for downloading files
109
+ """
110
+ # Authentication Settings
111
+ self.api_key = {}
112
+ if api_key:
113
+ self.api_key = api_key
114
+ """dict to store API key(s)
115
+ """
116
+ self.api_key_prefix = {}
117
+ if api_key_prefix:
118
+ self.api_key_prefix = api_key_prefix
119
+ """dict to store API prefix (e.g. Bearer)
120
+ """
121
+ self.refresh_api_key_hook = None
122
+ """function hook to refresh API key if expired
123
+ """
124
+ self.username = username
125
+ """Username for HTTP basic authentication
126
+ """
127
+ self.password = password
128
+ """Password for HTTP basic authentication
129
+ """
130
+ self.access_token = access_token
131
+ """Access token
132
+ """
133
+ self.logger = {}
134
+ """Logging Settings
135
+ """
136
+ self.logger["package_logger"] = logging.getLogger("admin_api_lib.rag_backend_client.openapi_client")
137
+ self.logger["urllib3_logger"] = logging.getLogger("urllib3")
138
+ self.logger_format = "%(asctime)s %(levelname)s %(message)s"
139
+ """Log format
140
+ """
141
+ self.logger_stream_handler = None
142
+ """Log stream handler
143
+ """
144
+ self.logger_file_handler: Optional[FileHandler] = None
145
+ """Log file handler
146
+ """
147
+ self.logger_file = None
148
+ """Debug file location
149
+ """
150
+ if debug is not None:
151
+ self.debug = debug
152
+ else:
153
+ self.__debug = False
154
+ """Debug switch
155
+ """
156
+
157
+ self.verify_ssl = True
158
+ """SSL/TLS verification
159
+ Set this to false to skip verifying SSL certificate when calling API
160
+ from https server.
161
+ """
162
+ self.ssl_ca_cert = ssl_ca_cert
163
+ """Set this to customize the certificate file to verify the peer.
164
+ """
165
+ self.cert_file = None
166
+ """client certificate file
167
+ """
168
+ self.key_file = None
169
+ """client key file
170
+ """
171
+ self.assert_hostname = None
172
+ """Set this to True/False to enable/disable SSL hostname verification.
173
+ """
174
+ self.tls_server_name = None
175
+ """SSL/TLS Server Name Indication (SNI)
176
+ Set this to the SNI value expected by the server.
177
+ """
178
+
179
+ self.connection_pool_maxsize = multiprocessing.cpu_count() * 5
180
+ """urllib3 connection pool's maximum number of connections saved
181
+ per pool. urllib3 uses 1 connection as default value, but this is
182
+ not the best value when you are making a lot of possibly parallel
183
+ requests to the same host, which is often the case here.
184
+ cpu_count * 5 is used as default value to increase performance.
185
+ """
186
+
187
+ self.proxy: Optional[str] = None
188
+ """Proxy URL
189
+ """
190
+ self.proxy_headers = None
191
+ """Proxy headers
192
+ """
193
+ self.safe_chars_for_path_param = ""
194
+ """Safe chars for path_param
195
+ """
196
+ self.retries = retries
197
+ """Adding retries to override urllib3 default value 3
198
+ """
199
+ # Enable client side validation
200
+ self.client_side_validation = True
201
+
202
+ self.socket_options = None
203
+ """Options to pass down to the underlying urllib3 socket
204
+ """
205
+
206
+ self.datetime_format = "%Y-%m-%dT%H:%M:%S.%f%z"
207
+ """datetime format
208
+ """
209
+
210
+ self.date_format = "%Y-%m-%d"
211
+ """date format
212
+ """
213
+
214
+ def __deepcopy__(self, memo):
215
+ cls = self.__class__
216
+ result = cls.__new__(cls)
217
+ memo[id(self)] = result
218
+ for k, v in self.__dict__.items():
219
+ if k not in ("logger", "logger_file_handler"):
220
+ setattr(result, k, copy.deepcopy(v, memo))
221
+ # shallow copy of loggers
222
+ result.logger = copy.copy(self.logger)
223
+ # use setters to configure loggers
224
+ result.logger_file = self.logger_file
225
+ result.debug = self.debug
226
+ return result
227
+
228
+ def __setattr__(self, name, value):
229
+ object.__setattr__(self, name, value)
230
+
231
+ @classmethod
232
+ def set_default(cls, default):
233
+ """Set default instance of configuration.
234
+
235
+ It stores default configuration, which can be
236
+ returned by get_default_copy method.
237
+
238
+ :param default: object of Configuration
239
+ """
240
+ cls._default = default
241
+
242
+ @classmethod
243
+ def get_default_copy(cls):
244
+ """Deprecated. Please use `get_default` instead.
245
+
246
+ Deprecated. Please use `get_default` instead.
247
+
248
+ :return: The configuration object.
249
+ """
250
+ return cls.get_default()
251
+
252
+ @classmethod
253
+ def get_default(cls):
254
+ """Return the default configuration.
255
+
256
+ This method returns newly created, based on default constructor,
257
+ object of Configuration class or returns a copy of default
258
+ configuration.
259
+
260
+ :return: The configuration object.
261
+ """
262
+ if cls._default is None:
263
+ cls._default = Configuration()
264
+ return cls._default
265
+
266
+ @property
267
+ def logger_file(self):
268
+ """The logger file.
269
+
270
+ If the logger_file is None, then add stream handler and remove file
271
+ handler. Otherwise, add file handler and remove stream handler.
272
+
273
+ :param value: The logger_file path.
274
+ :type: str
275
+ """
276
+ return self.__logger_file
277
+
278
+ @logger_file.setter
279
+ def logger_file(self, value):
280
+ """The logger file.
281
+
282
+ If the logger_file is None, then add stream handler and remove file
283
+ handler. Otherwise, add file handler and remove stream handler.
284
+
285
+ :param value: The logger_file path.
286
+ :type: str
287
+ """
288
+ self.__logger_file = value
289
+ if self.__logger_file:
290
+ # If set logging file,
291
+ # then add file handler and remove stream handler.
292
+ self.logger_file_handler = logging.FileHandler(self.__logger_file)
293
+ self.logger_file_handler.setFormatter(self.logger_formatter)
294
+ for _, logger in self.logger.items():
295
+ logger.addHandler(self.logger_file_handler)
296
+
297
+ @property
298
+ def debug(self):
299
+ """Debug status
300
+
301
+ :param value: The debug status, True or False.
302
+ :type: bool
303
+ """
304
+ return self.__debug
305
+
306
+ @debug.setter
307
+ def debug(self, value):
308
+ """Debug status
309
+
310
+ :param value: The debug status, True or False.
311
+ :type: bool
312
+ """
313
+ self.__debug = value
314
+ if self.__debug:
315
+ # if debug status is True, turn on debug logging
316
+ for _, logger in self.logger.items():
317
+ logger.setLevel(logging.DEBUG)
318
+ # turn on httplib debug
319
+ httplib.HTTPConnection.debuglevel = 1
320
+ else:
321
+ # if debug status is False, turn off debug logging,
322
+ # setting log level to default `logging.WARNING`
323
+ for _, logger in self.logger.items():
324
+ logger.setLevel(logging.WARNING)
325
+ # turn off httplib debug
326
+ httplib.HTTPConnection.debuglevel = 0
327
+
328
+ @property
329
+ def logger_format(self):
330
+ """The logger format.
331
+
332
+ The logger_formatter will be updated when sets logger_format.
333
+
334
+ :param value: The format string.
335
+ :type: str
336
+ """
337
+ return self.__logger_format
338
+
339
+ @logger_format.setter
340
+ def logger_format(self, value):
341
+ """The logger format.
342
+
343
+ The logger_formatter will be updated when sets logger_format.
344
+
345
+ :param value: The format string.
346
+ :type: str
347
+ """
348
+ self.__logger_format = value
349
+ self.logger_formatter = logging.Formatter(self.__logger_format)
350
+
351
+ def get_api_key_with_prefix(self, identifier, alias=None):
352
+ """Gets API key (with prefix if set).
353
+
354
+ :param identifier: The identifier of apiKey.
355
+ :param alias: The alternative identifier of apiKey.
356
+ :return: The token for api key authentication.
357
+ """
358
+ if self.refresh_api_key_hook is not None:
359
+ self.refresh_api_key_hook(self)
360
+ key = self.api_key.get(identifier, self.api_key.get(alias) if alias is not None else None)
361
+ if key:
362
+ prefix = self.api_key_prefix.get(identifier)
363
+ if prefix:
364
+ return "%s %s" % (prefix, key)
365
+ else:
366
+ return key
367
+
368
+ def get_basic_auth_token(self):
369
+ """Gets HTTP basic authentication header (string).
370
+
371
+ :return: The token for basic HTTP authentication.
372
+ """
373
+ username = ""
374
+ if self.username is not None:
375
+ username = self.username
376
+ password = ""
377
+ if self.password is not None:
378
+ password = self.password
379
+ return urllib3.util.make_headers(basic_auth=username + ":" + password).get("authorization")
380
+
381
+ def auth_settings(self):
382
+ """Gets Auth Settings dict for api client.
383
+
384
+ :return: The Auth Settings information dict.
385
+ """
386
+ auth = {}
387
+ return auth
388
+
389
+ def to_debug_report(self):
390
+ """Gets the essential information for debugging.
391
+
392
+ :return: The report for debugging.
393
+ """
394
+ return (
395
+ "Python SDK Debug Report:\n"
396
+ "OS: {env}\n"
397
+ "Python Version: {pyversion}\n"
398
+ "Version of the API: 1.0.0\n"
399
+ "SDK Package Version: 1.0.0".format(env=sys.platform, pyversion=sys.version)
400
+ )
401
+
402
+ def get_host_settings(self):
403
+ """Gets an array of host settings
404
+
405
+ :return: An array of host settings
406
+ """
407
+ return [
408
+ {
409
+ "url": "",
410
+ "description": "No description provided",
411
+ }
412
+ ]
413
+
414
+ def get_host_from_settings(self, index, variables=None, servers=None):
415
+ """Gets host URL based on the index and variables
416
+ :param index: array index of the host settings
417
+ :param variables: hash of variable and the corresponding value
418
+ :param servers: an array of host settings or None
419
+ :return: URL based on host settings
420
+ """
421
+ if index is None:
422
+ return self._base_path
423
+
424
+ variables = {} if variables is None else variables
425
+ servers = self.get_host_settings() if servers is None else servers
426
+
427
+ try:
428
+ server = servers[index]
429
+ except IndexError:
430
+ raise ValueError(
431
+ "Invalid index {0} when selecting the host settings. "
432
+ "Must be less than {1}".format(index, len(servers))
433
+ )
434
+
435
+ url = server["url"]
436
+
437
+ # go through variables and replace placeholders
438
+ for variable_name, variable in server.get("variables", {}).items():
439
+ used_value = variables.get(variable_name, variable["default_value"])
440
+
441
+ if "enum_values" in variable and used_value not in variable["enum_values"]:
442
+ raise ValueError(
443
+ "The variable `{0}` in the host URL has invalid value "
444
+ "{1}. Must be {2}.".format(variable_name, variables[variable_name], variable["enum_values"])
445
+ )
446
+
447
+ url = url.replace("{" + variable_name + "}", used_value)
448
+
449
+ return url
450
+
451
+ @property
452
+ def host(self):
453
+ """Return generated host."""
454
+ return self.get_host_from_settings(self.server_index, variables=self.server_variables)
455
+
456
+ @host.setter
457
+ def host(self, value):
458
+ """Fix base path."""
459
+ self._base_path = value
460
+ self.server_index = None
@@ -0,0 +1,197 @@
1
+ # coding: utf-8
2
+
3
+ """
4
+ STACKIT RAG
5
+
6
+ The perfect rag solution.
7
+
8
+ The version of the OpenAPI document: 1.0.0
9
+ Generated by OpenAPI Generator (https://openapi-generator.tech)
10
+
11
+ Do not edit the class manually.
12
+ """ # noqa: E501
13
+
14
+ from typing import Any, Optional
15
+
16
+ from typing_extensions import Self
17
+
18
+
19
+ class OpenApiException(Exception):
20
+ """The base exception class for all OpenAPIExceptions"""
21
+
22
+
23
+ class ApiTypeError(OpenApiException, TypeError):
24
+ def __init__(self, msg, path_to_item=None, valid_classes=None, key_type=None) -> None:
25
+ """Raises an exception for TypeErrors
26
+
27
+ Args:
28
+ msg (str): the exception message
29
+
30
+ Keyword Args:
31
+ path_to_item (list): a list of keys an indices to get to the
32
+ current_item
33
+ None if unset
34
+ valid_classes (tuple): the primitive classes that current item
35
+ should be an instance of
36
+ None if unset
37
+ key_type (bool): False if our value is a value in a dict
38
+ True if it is a key in a dict
39
+ False if our item is an item in a list
40
+ None if unset
41
+ """
42
+ self.path_to_item = path_to_item
43
+ self.valid_classes = valid_classes
44
+ self.key_type = key_type
45
+ full_msg = msg
46
+ if path_to_item:
47
+ full_msg = "{0} at {1}".format(msg, render_path(path_to_item))
48
+ super(ApiTypeError, self).__init__(full_msg)
49
+
50
+
51
+ class ApiValueError(OpenApiException, ValueError):
52
+ def __init__(self, msg, path_to_item=None) -> None:
53
+ """
54
+ Args:
55
+ msg (str): the exception message
56
+
57
+ Keyword Args:
58
+ path_to_item (list) the path to the exception in the
59
+ received_data dict. None if unset
60
+ """
61
+
62
+ self.path_to_item = path_to_item
63
+ full_msg = msg
64
+ if path_to_item:
65
+ full_msg = "{0} at {1}".format(msg, render_path(path_to_item))
66
+ super(ApiValueError, self).__init__(full_msg)
67
+
68
+
69
+ class ApiAttributeError(OpenApiException, AttributeError):
70
+ def __init__(self, msg, path_to_item=None) -> None:
71
+ """
72
+ Raised when an attribute reference or assignment fails.
73
+
74
+ Args:
75
+ msg (str): the exception message
76
+
77
+ Keyword Args:
78
+ path_to_item (None/list) the path to the exception in the
79
+ received_data dict
80
+ """
81
+ self.path_to_item = path_to_item
82
+ full_msg = msg
83
+ if path_to_item:
84
+ full_msg = "{0} at {1}".format(msg, render_path(path_to_item))
85
+ super(ApiAttributeError, self).__init__(full_msg)
86
+
87
+
88
+ class ApiKeyError(OpenApiException, KeyError):
89
+ def __init__(self, msg, path_to_item=None) -> None:
90
+ """
91
+ Args:
92
+ msg (str): the exception message
93
+
94
+ Keyword Args:
95
+ path_to_item (None/list) the path to the exception in the
96
+ received_data dict
97
+ """
98
+ self.path_to_item = path_to_item
99
+ full_msg = msg
100
+ if path_to_item:
101
+ full_msg = "{0} at {1}".format(msg, render_path(path_to_item))
102
+ super(ApiKeyError, self).__init__(full_msg)
103
+
104
+
105
+ class ApiException(OpenApiException):
106
+ def __init__(
107
+ self,
108
+ status=None,
109
+ reason=None,
110
+ http_resp=None,
111
+ *,
112
+ body: Optional[str] = None,
113
+ data: Optional[Any] = None,
114
+ ) -> None:
115
+ self.status = status
116
+ self.reason = reason
117
+ self.body = body
118
+ self.data = data
119
+ self.headers = None
120
+
121
+ if http_resp:
122
+ if self.status is None:
123
+ self.status = http_resp.status
124
+ if self.reason is None:
125
+ self.reason = http_resp.reason
126
+ if self.body is None:
127
+ try:
128
+ self.body = http_resp.data.decode("utf-8")
129
+ except Exception:
130
+ pass
131
+ self.headers = http_resp.getheaders()
132
+
133
+ @classmethod
134
+ def from_response(
135
+ cls,
136
+ *,
137
+ http_resp,
138
+ body: Optional[str],
139
+ data: Optional[Any],
140
+ ) -> Self:
141
+ if http_resp.status == 400:
142
+ raise BadRequestException(http_resp=http_resp, body=body, data=data)
143
+
144
+ if http_resp.status == 401:
145
+ raise UnauthorizedException(http_resp=http_resp, body=body, data=data)
146
+
147
+ if http_resp.status == 403:
148
+ raise ForbiddenException(http_resp=http_resp, body=body, data=data)
149
+
150
+ if http_resp.status == 404:
151
+ raise NotFoundException(http_resp=http_resp, body=body, data=data)
152
+
153
+ if 500 <= http_resp.status <= 599:
154
+ raise ServiceException(http_resp=http_resp, body=body, data=data)
155
+ raise ApiException(http_resp=http_resp, body=body, data=data)
156
+
157
+ def __str__(self):
158
+ """Custom error messages for exception"""
159
+ error_message = "({0})\n" "Reason: {1}\n".format(self.status, self.reason)
160
+ if self.headers:
161
+ error_message += "HTTP response headers: {0}\n".format(self.headers)
162
+
163
+ if self.data or self.body:
164
+ error_message += "HTTP response body: {0}\n".format(self.data or self.body)
165
+
166
+ return error_message
167
+
168
+
169
+ class BadRequestException(ApiException):
170
+ pass
171
+
172
+
173
+ class NotFoundException(ApiException):
174
+ pass
175
+
176
+
177
+ class UnauthorizedException(ApiException):
178
+ pass
179
+
180
+
181
+ class ForbiddenException(ApiException):
182
+ pass
183
+
184
+
185
+ class ServiceException(ApiException):
186
+ pass
187
+
188
+
189
+ def render_path(path_to_item):
190
+ """Returns a string representation of a path"""
191
+ result = ""
192
+ for pth in path_to_item:
193
+ if isinstance(pth, int):
194
+ result += "[{0}]".format(pth)
195
+ else:
196
+ result += "['{0}']".format(pth)
197
+ return result