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.
- admin_api_lib/__init__.py +0 -0
- admin_api_lib/api_endpoints/document_deleter.py +24 -0
- admin_api_lib/api_endpoints/document_reference_retriever.py +25 -0
- admin_api_lib/api_endpoints/documents_status_retriever.py +20 -0
- admin_api_lib/api_endpoints/file_uploader.py +31 -0
- admin_api_lib/api_endpoints/source_uploader.py +40 -0
- admin_api_lib/api_endpoints/uploader_base.py +30 -0
- admin_api_lib/apis/__init__.py +0 -0
- admin_api_lib/apis/admin_api.py +197 -0
- admin_api_lib/apis/admin_api_base.py +120 -0
- admin_api_lib/chunker/__init__.py +0 -0
- admin_api_lib/chunker/chunker.py +25 -0
- admin_api_lib/dependency_container.py +236 -0
- admin_api_lib/extractor_api_client/__init__.py +0 -0
- admin_api_lib/extractor_api_client/openapi_client/__init__.py +38 -0
- admin_api_lib/extractor_api_client/openapi_client/api/__init__.py +4 -0
- admin_api_lib/extractor_api_client/openapi_client/api/extractor_api.py +516 -0
- admin_api_lib/extractor_api_client/openapi_client/api_client.py +695 -0
- admin_api_lib/extractor_api_client/openapi_client/api_response.py +20 -0
- admin_api_lib/extractor_api_client/openapi_client/configuration.py +460 -0
- admin_api_lib/extractor_api_client/openapi_client/exceptions.py +197 -0
- admin_api_lib/extractor_api_client/openapi_client/models/__init__.py +21 -0
- admin_api_lib/extractor_api_client/openapi_client/models/content_type.py +34 -0
- admin_api_lib/extractor_api_client/openapi_client/models/extraction_parameters.py +103 -0
- admin_api_lib/extractor_api_client/openapi_client/models/extraction_request.py +82 -0
- admin_api_lib/extractor_api_client/openapi_client/models/information_piece.py +104 -0
- admin_api_lib/extractor_api_client/openapi_client/models/key_value_pair.py +92 -0
- admin_api_lib/extractor_api_client/openapi_client/rest.py +209 -0
- admin_api_lib/extractor_api_client/openapi_client/test/__init__.py +0 -0
- admin_api_lib/extractor_api_client/openapi_client/test/test_content_type.py +35 -0
- admin_api_lib/extractor_api_client/openapi_client/test/test_extraction_parameters.py +59 -0
- admin_api_lib/extractor_api_client/openapi_client/test/test_extraction_request.py +56 -0
- admin_api_lib/extractor_api_client/openapi_client/test/test_extractor_api.py +39 -0
- admin_api_lib/extractor_api_client/openapi_client/test/test_information_piece.py +62 -0
- admin_api_lib/extractor_api_client/openapi_client/test/test_key_value_pair.py +54 -0
- admin_api_lib/file_services/file_service.py +77 -0
- admin_api_lib/impl/__init__.py +0 -0
- admin_api_lib/impl/admin_api.py +167 -0
- admin_api_lib/impl/api_endpoints/default_document_deleter.py +84 -0
- admin_api_lib/impl/api_endpoints/default_document_reference_retriever.py +72 -0
- admin_api_lib/impl/api_endpoints/default_documents_status_retriever.py +41 -0
- admin_api_lib/impl/api_endpoints/default_file_uploader.py +234 -0
- admin_api_lib/impl/api_endpoints/default_source_uploader.py +202 -0
- admin_api_lib/impl/chunker/__init__.py +0 -0
- admin_api_lib/impl/chunker/chunker_type.py +11 -0
- admin_api_lib/impl/chunker/semantic_text_chunker.py +252 -0
- admin_api_lib/impl/chunker/text_chunker.py +33 -0
- admin_api_lib/impl/file_services/__init__.py +0 -0
- admin_api_lib/impl/file_services/s3_service.py +130 -0
- admin_api_lib/impl/information_enhancer/__init__.py +0 -0
- admin_api_lib/impl/information_enhancer/general_enhancer.py +52 -0
- admin_api_lib/impl/information_enhancer/page_summary_enhancer.py +62 -0
- admin_api_lib/impl/information_enhancer/summary_enhancer.py +74 -0
- admin_api_lib/impl/key_db/__init__.py +0 -0
- admin_api_lib/impl/key_db/file_status_key_value_store.py +111 -0
- admin_api_lib/impl/mapper/informationpiece2document.py +108 -0
- admin_api_lib/impl/settings/__init__.py +0 -0
- admin_api_lib/impl/settings/chunker_class_type_settings.py +18 -0
- admin_api_lib/impl/settings/chunker_settings.py +29 -0
- admin_api_lib/impl/settings/document_extractor_settings.py +21 -0
- admin_api_lib/impl/settings/key_value_settings.py +26 -0
- admin_api_lib/impl/settings/rag_api_settings.py +21 -0
- admin_api_lib/impl/settings/s3_settings.py +31 -0
- admin_api_lib/impl/settings/source_uploader_settings.py +23 -0
- admin_api_lib/impl/settings/summarizer_settings.py +86 -0
- admin_api_lib/impl/summarizer/__init__.py +0 -0
- admin_api_lib/impl/summarizer/langchain_summarizer.py +117 -0
- admin_api_lib/information_enhancer/__init__.py +0 -0
- admin_api_lib/information_enhancer/information_enhancer.py +34 -0
- admin_api_lib/main.py +54 -0
- admin_api_lib/models/__init__.py +0 -0
- admin_api_lib/models/document_status.py +86 -0
- admin_api_lib/models/extra_models.py +9 -0
- admin_api_lib/models/http_validation_error.py +105 -0
- admin_api_lib/models/key_value_pair.py +85 -0
- admin_api_lib/models/status.py +44 -0
- admin_api_lib/models/validation_error.py +104 -0
- admin_api_lib/models/validation_error_loc_inner.py +114 -0
- admin_api_lib/prompt_templates/__init__.py +0 -0
- admin_api_lib/prompt_templates/summarize_prompt.py +14 -0
- admin_api_lib/rag_backend_client/__init__.py +0 -0
- admin_api_lib/rag_backend_client/openapi_client/__init__.py +60 -0
- admin_api_lib/rag_backend_client/openapi_client/api/__init__.py +4 -0
- admin_api_lib/rag_backend_client/openapi_client/api/rag_api.py +968 -0
- admin_api_lib/rag_backend_client/openapi_client/api_client.py +698 -0
- admin_api_lib/rag_backend_client/openapi_client/api_response.py +22 -0
- admin_api_lib/rag_backend_client/openapi_client/configuration.py +460 -0
- admin_api_lib/rag_backend_client/openapi_client/exceptions.py +197 -0
- admin_api_lib/rag_backend_client/openapi_client/models/__init__.py +41 -0
- admin_api_lib/rag_backend_client/openapi_client/models/chat_history.py +99 -0
- admin_api_lib/rag_backend_client/openapi_client/models/chat_history_message.py +83 -0
- admin_api_lib/rag_backend_client/openapi_client/models/chat_request.py +93 -0
- admin_api_lib/rag_backend_client/openapi_client/models/chat_response.py +103 -0
- admin_api_lib/rag_backend_client/openapi_client/models/chat_role.py +35 -0
- admin_api_lib/rag_backend_client/openapi_client/models/content_type.py +37 -0
- admin_api_lib/rag_backend_client/openapi_client/models/delete_request.py +99 -0
- admin_api_lib/rag_backend_client/openapi_client/models/information_piece.py +110 -0
- admin_api_lib/rag_backend_client/openapi_client/models/key_value_pair.py +83 -0
- admin_api_lib/rag_backend_client/openapi_client/rest.py +209 -0
- admin_api_lib/summarizer/__init__.py +0 -0
- admin_api_lib/summarizer/summarizer.py +33 -0
- admin_api_lib/utils/__init__.py +0 -0
- admin_api_lib/utils/utils.py +32 -0
- admin_api_lib-3.2.0.dist-info/METADATA +24 -0
- admin_api_lib-3.2.0.dist-info/RECORD +106 -0
- admin_api_lib-3.2.0.dist-info/WHEEL +4 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
|
|
3
|
+
"""
|
|
4
|
+
extractor-api-lib
|
|
5
|
+
|
|
6
|
+
No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
|
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
|
+
from __future__ import annotations
|
|
16
|
+
import json
|
|
17
|
+
from enum import Enum
|
|
18
|
+
from typing_extensions import Self
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class ContentType(str, Enum):
|
|
22
|
+
""" """
|
|
23
|
+
|
|
24
|
+
"""
|
|
25
|
+
allowed enum values
|
|
26
|
+
"""
|
|
27
|
+
IMAGE = "IMAGE"
|
|
28
|
+
TABLE = "TABLE"
|
|
29
|
+
TEXT = "TEXT"
|
|
30
|
+
|
|
31
|
+
@classmethod
|
|
32
|
+
def from_json(cls, json_str: str) -> Self:
|
|
33
|
+
"""Create an instance of ContentType from a JSON string"""
|
|
34
|
+
return cls(json.loads(json_str))
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
|
|
3
|
+
"""
|
|
4
|
+
extractor-api-lib
|
|
5
|
+
|
|
6
|
+
No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
|
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
|
+
from __future__ import annotations
|
|
16
|
+
import pprint
|
|
17
|
+
import re # noqa: F401
|
|
18
|
+
import json
|
|
19
|
+
|
|
20
|
+
from pydantic import BaseModel, ConfigDict, Field, StrictStr
|
|
21
|
+
from typing import Any, ClassVar, Dict, List, Optional
|
|
22
|
+
from admin_api_lib.extractor_api_client.openapi_client.models.key_value_pair import KeyValuePair
|
|
23
|
+
from typing import Optional, Set
|
|
24
|
+
from typing_extensions import Self
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class ExtractionParameters(BaseModel):
|
|
28
|
+
""" """ # noqa: E501
|
|
29
|
+
|
|
30
|
+
document_name: StrictStr = Field(
|
|
31
|
+
description="The name that will be used to store the confluence db in the key value db and the vectordatabase (metadata.document)."
|
|
32
|
+
)
|
|
33
|
+
kwargs: Optional[List[KeyValuePair]] = Field(default=None, description="Kwargs for the extractor")
|
|
34
|
+
source_type: StrictStr = Field(description="Extractortype")
|
|
35
|
+
__properties: ClassVar[List[str]] = ["document_name", "kwargs", "source_type"]
|
|
36
|
+
|
|
37
|
+
model_config = ConfigDict(
|
|
38
|
+
populate_by_name=True,
|
|
39
|
+
validate_assignment=True,
|
|
40
|
+
protected_namespaces=(),
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
def to_str(self) -> str:
|
|
44
|
+
"""Returns the string representation of the model using alias"""
|
|
45
|
+
return pprint.pformat(self.model_dump(by_alias=True))
|
|
46
|
+
|
|
47
|
+
def to_json(self) -> str:
|
|
48
|
+
"""Returns the JSON representation of the model using alias"""
|
|
49
|
+
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
|
|
50
|
+
return json.dumps(self.to_dict())
|
|
51
|
+
|
|
52
|
+
@classmethod
|
|
53
|
+
def from_json(cls, json_str: str) -> Optional[Self]:
|
|
54
|
+
"""Create an instance of ExtractionParameters from a JSON string"""
|
|
55
|
+
return cls.from_dict(json.loads(json_str))
|
|
56
|
+
|
|
57
|
+
def to_dict(self) -> Dict[str, Any]:
|
|
58
|
+
"""Return the dictionary representation of the model using alias.
|
|
59
|
+
|
|
60
|
+
This has the following differences from calling pydantic's
|
|
61
|
+
`self.model_dump(by_alias=True)`:
|
|
62
|
+
|
|
63
|
+
* `None` is only added to the output dict for nullable fields that
|
|
64
|
+
were set at model initialization. Other fields with value `None`
|
|
65
|
+
are ignored.
|
|
66
|
+
"""
|
|
67
|
+
excluded_fields: Set[str] = set([])
|
|
68
|
+
|
|
69
|
+
_dict = self.model_dump(
|
|
70
|
+
by_alias=True,
|
|
71
|
+
exclude=excluded_fields,
|
|
72
|
+
exclude_none=True,
|
|
73
|
+
)
|
|
74
|
+
# override the default output from pydantic by calling `to_dict()` of each item in kwargs (list)
|
|
75
|
+
_items = []
|
|
76
|
+
if self.kwargs:
|
|
77
|
+
for _item_kwargs in self.kwargs:
|
|
78
|
+
if _item_kwargs:
|
|
79
|
+
_items.append(_item_kwargs.to_dict())
|
|
80
|
+
_dict["kwargs"] = _items
|
|
81
|
+
return _dict
|
|
82
|
+
|
|
83
|
+
@classmethod
|
|
84
|
+
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
|
|
85
|
+
"""Create an instance of ExtractionParameters from a dict"""
|
|
86
|
+
if obj is None:
|
|
87
|
+
return None
|
|
88
|
+
|
|
89
|
+
if not isinstance(obj, dict):
|
|
90
|
+
return cls.model_validate(obj)
|
|
91
|
+
|
|
92
|
+
_obj = cls.model_validate(
|
|
93
|
+
{
|
|
94
|
+
"document_name": obj.get("document_name"),
|
|
95
|
+
"kwargs": (
|
|
96
|
+
[KeyValuePair.from_dict(_item) for _item in obj["kwargs"]]
|
|
97
|
+
if obj.get("kwargs") is not None
|
|
98
|
+
else None
|
|
99
|
+
),
|
|
100
|
+
"source_type": obj.get("source_type"),
|
|
101
|
+
}
|
|
102
|
+
)
|
|
103
|
+
return _obj
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
|
|
3
|
+
"""
|
|
4
|
+
extractor-api-lib
|
|
5
|
+
|
|
6
|
+
No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
|
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
|
+
from __future__ import annotations
|
|
16
|
+
import pprint
|
|
17
|
+
import re # noqa: F401
|
|
18
|
+
import json
|
|
19
|
+
|
|
20
|
+
from pydantic import BaseModel, ConfigDict, StrictStr
|
|
21
|
+
from typing import Any, ClassVar, Dict, List
|
|
22
|
+
from typing import Optional, Set
|
|
23
|
+
from typing_extensions import Self
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class ExtractionRequest(BaseModel):
|
|
27
|
+
""" """ # noqa: E501
|
|
28
|
+
|
|
29
|
+
path_on_s3: StrictStr
|
|
30
|
+
document_name: StrictStr
|
|
31
|
+
__properties: ClassVar[List[str]] = ["path_on_s3", "document_name"]
|
|
32
|
+
|
|
33
|
+
model_config = ConfigDict(
|
|
34
|
+
populate_by_name=True,
|
|
35
|
+
validate_assignment=True,
|
|
36
|
+
protected_namespaces=(),
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
def to_str(self) -> str:
|
|
40
|
+
"""Returns the string representation of the model using alias"""
|
|
41
|
+
return pprint.pformat(self.model_dump(by_alias=True))
|
|
42
|
+
|
|
43
|
+
def to_json(self) -> str:
|
|
44
|
+
"""Returns the JSON representation of the model using alias"""
|
|
45
|
+
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
|
|
46
|
+
return json.dumps(self.to_dict())
|
|
47
|
+
|
|
48
|
+
@classmethod
|
|
49
|
+
def from_json(cls, json_str: str) -> Optional[Self]:
|
|
50
|
+
"""Create an instance of ExtractionRequest from a JSON string"""
|
|
51
|
+
return cls.from_dict(json.loads(json_str))
|
|
52
|
+
|
|
53
|
+
def to_dict(self) -> Dict[str, Any]:
|
|
54
|
+
"""Return the dictionary representation of the model using alias.
|
|
55
|
+
|
|
56
|
+
This has the following differences from calling pydantic's
|
|
57
|
+
`self.model_dump(by_alias=True)`:
|
|
58
|
+
|
|
59
|
+
* `None` is only added to the output dict for nullable fields that
|
|
60
|
+
were set at model initialization. Other fields with value `None`
|
|
61
|
+
are ignored.
|
|
62
|
+
"""
|
|
63
|
+
excluded_fields: Set[str] = set([])
|
|
64
|
+
|
|
65
|
+
_dict = self.model_dump(
|
|
66
|
+
by_alias=True,
|
|
67
|
+
exclude=excluded_fields,
|
|
68
|
+
exclude_none=True,
|
|
69
|
+
)
|
|
70
|
+
return _dict
|
|
71
|
+
|
|
72
|
+
@classmethod
|
|
73
|
+
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
|
|
74
|
+
"""Create an instance of ExtractionRequest from a dict"""
|
|
75
|
+
if obj is None:
|
|
76
|
+
return None
|
|
77
|
+
|
|
78
|
+
if not isinstance(obj, dict):
|
|
79
|
+
return cls.model_validate(obj)
|
|
80
|
+
|
|
81
|
+
_obj = cls.model_validate({"path_on_s3": obj.get("path_on_s3"), "document_name": obj.get("document_name")})
|
|
82
|
+
return _obj
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
|
|
3
|
+
"""
|
|
4
|
+
extractor-api-lib
|
|
5
|
+
|
|
6
|
+
No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
|
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
|
+
from __future__ import annotations
|
|
16
|
+
import pprint
|
|
17
|
+
import re # noqa: F401
|
|
18
|
+
import json
|
|
19
|
+
|
|
20
|
+
from pydantic import BaseModel, ConfigDict, StrictStr
|
|
21
|
+
from typing import Any, ClassVar, Dict, List
|
|
22
|
+
from admin_api_lib.extractor_api_client.openapi_client.models.content_type import ContentType
|
|
23
|
+
from admin_api_lib.extractor_api_client.openapi_client.models.key_value_pair import KeyValuePair
|
|
24
|
+
from typing import Optional, Set
|
|
25
|
+
from typing_extensions import Self
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class InformationPiece(BaseModel):
|
|
29
|
+
"""
|
|
30
|
+
A piece of information that has been extracted.
|
|
31
|
+
""" # noqa: E501
|
|
32
|
+
|
|
33
|
+
metadata: List[KeyValuePair]
|
|
34
|
+
page_content: StrictStr
|
|
35
|
+
type: ContentType
|
|
36
|
+
__properties: ClassVar[List[str]] = ["metadata", "page_content", "type"]
|
|
37
|
+
|
|
38
|
+
model_config = ConfigDict(
|
|
39
|
+
populate_by_name=True,
|
|
40
|
+
validate_assignment=True,
|
|
41
|
+
protected_namespaces=(),
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
def to_str(self) -> str:
|
|
45
|
+
"""Returns the string representation of the model using alias"""
|
|
46
|
+
return pprint.pformat(self.model_dump(by_alias=True))
|
|
47
|
+
|
|
48
|
+
def to_json(self) -> str:
|
|
49
|
+
"""Returns the JSON representation of the model using alias"""
|
|
50
|
+
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
|
|
51
|
+
return json.dumps(self.to_dict())
|
|
52
|
+
|
|
53
|
+
@classmethod
|
|
54
|
+
def from_json(cls, json_str: str) -> Optional[Self]:
|
|
55
|
+
"""Create an instance of InformationPiece from a JSON string"""
|
|
56
|
+
return cls.from_dict(json.loads(json_str))
|
|
57
|
+
|
|
58
|
+
def to_dict(self) -> Dict[str, Any]:
|
|
59
|
+
"""Return the dictionary representation of the model using alias.
|
|
60
|
+
|
|
61
|
+
This has the following differences from calling pydantic's
|
|
62
|
+
`self.model_dump(by_alias=True)`:
|
|
63
|
+
|
|
64
|
+
* `None` is only added to the output dict for nullable fields that
|
|
65
|
+
were set at model initialization. Other fields with value `None`
|
|
66
|
+
are ignored.
|
|
67
|
+
"""
|
|
68
|
+
excluded_fields: Set[str] = set([])
|
|
69
|
+
|
|
70
|
+
_dict = self.model_dump(
|
|
71
|
+
by_alias=True,
|
|
72
|
+
exclude=excluded_fields,
|
|
73
|
+
exclude_none=True,
|
|
74
|
+
)
|
|
75
|
+
# override the default output from pydantic by calling `to_dict()` of each item in metadata (list)
|
|
76
|
+
_items = []
|
|
77
|
+
if self.metadata:
|
|
78
|
+
for _item_metadata in self.metadata:
|
|
79
|
+
if _item_metadata:
|
|
80
|
+
_items.append(_item_metadata.to_dict())
|
|
81
|
+
_dict["metadata"] = _items
|
|
82
|
+
return _dict
|
|
83
|
+
|
|
84
|
+
@classmethod
|
|
85
|
+
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
|
|
86
|
+
"""Create an instance of InformationPiece from a dict"""
|
|
87
|
+
if obj is None:
|
|
88
|
+
return None
|
|
89
|
+
|
|
90
|
+
if not isinstance(obj, dict):
|
|
91
|
+
return cls.model_validate(obj)
|
|
92
|
+
|
|
93
|
+
_obj = cls.model_validate(
|
|
94
|
+
{
|
|
95
|
+
"metadata": (
|
|
96
|
+
[KeyValuePair.from_dict(_item) for _item in obj["metadata"]]
|
|
97
|
+
if obj.get("metadata") is not None
|
|
98
|
+
else None
|
|
99
|
+
),
|
|
100
|
+
"page_content": obj.get("page_content"),
|
|
101
|
+
"type": obj.get("type"),
|
|
102
|
+
}
|
|
103
|
+
)
|
|
104
|
+
return _obj
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
|
|
3
|
+
"""
|
|
4
|
+
extractor-api-lib
|
|
5
|
+
|
|
6
|
+
No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
|
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
|
+
from __future__ import annotations
|
|
16
|
+
import pprint
|
|
17
|
+
import re # noqa: F401
|
|
18
|
+
import json
|
|
19
|
+
|
|
20
|
+
from pydantic import BaseModel, ConfigDict
|
|
21
|
+
from typing import Any, ClassVar, Dict, List, Optional
|
|
22
|
+
from typing import Optional, Set
|
|
23
|
+
from typing_extensions import Self
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class KeyValuePair(BaseModel):
|
|
27
|
+
""" """ # noqa: E501
|
|
28
|
+
|
|
29
|
+
key: Optional[Any] = None
|
|
30
|
+
value: Optional[Any] = None
|
|
31
|
+
__properties: ClassVar[List[str]] = ["key", "value"]
|
|
32
|
+
|
|
33
|
+
model_config = ConfigDict(
|
|
34
|
+
populate_by_name=True,
|
|
35
|
+
validate_assignment=True,
|
|
36
|
+
protected_namespaces=(),
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
def to_str(self) -> str:
|
|
40
|
+
"""Returns the string representation of the model using alias"""
|
|
41
|
+
return pprint.pformat(self.model_dump(by_alias=True))
|
|
42
|
+
|
|
43
|
+
def to_json(self) -> str:
|
|
44
|
+
"""Returns the JSON representation of the model using alias"""
|
|
45
|
+
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
|
|
46
|
+
return json.dumps(self.to_dict())
|
|
47
|
+
|
|
48
|
+
@classmethod
|
|
49
|
+
def from_json(cls, json_str: str) -> Optional[Self]:
|
|
50
|
+
"""Create an instance of KeyValuePair from a JSON string"""
|
|
51
|
+
return cls.from_dict(json.loads(json_str))
|
|
52
|
+
|
|
53
|
+
def to_dict(self) -> Dict[str, Any]:
|
|
54
|
+
"""Return the dictionary representation of the model using alias.
|
|
55
|
+
|
|
56
|
+
This has the following differences from calling pydantic's
|
|
57
|
+
`self.model_dump(by_alias=True)`:
|
|
58
|
+
|
|
59
|
+
* `None` is only added to the output dict for nullable fields that
|
|
60
|
+
were set at model initialization. Other fields with value `None`
|
|
61
|
+
are ignored.
|
|
62
|
+
"""
|
|
63
|
+
excluded_fields: Set[str] = set([])
|
|
64
|
+
|
|
65
|
+
_dict = self.model_dump(
|
|
66
|
+
by_alias=True,
|
|
67
|
+
exclude=excluded_fields,
|
|
68
|
+
exclude_none=True,
|
|
69
|
+
)
|
|
70
|
+
# set to None if key (nullable) is None
|
|
71
|
+
# and model_fields_set contains the field
|
|
72
|
+
if self.key is None and "key" in self.model_fields_set:
|
|
73
|
+
_dict["key"] = None
|
|
74
|
+
|
|
75
|
+
# set to None if value (nullable) is None
|
|
76
|
+
# and model_fields_set contains the field
|
|
77
|
+
if self.value is None and "value" in self.model_fields_set:
|
|
78
|
+
_dict["value"] = None
|
|
79
|
+
|
|
80
|
+
return _dict
|
|
81
|
+
|
|
82
|
+
@classmethod
|
|
83
|
+
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
|
|
84
|
+
"""Create an instance of KeyValuePair from a dict"""
|
|
85
|
+
if obj is None:
|
|
86
|
+
return None
|
|
87
|
+
|
|
88
|
+
if not isinstance(obj, dict):
|
|
89
|
+
return cls.model_validate(obj)
|
|
90
|
+
|
|
91
|
+
_obj = cls.model_validate({"key": obj.get("key"), "value": obj.get("value")})
|
|
92
|
+
return _obj
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
|
|
3
|
+
"""
|
|
4
|
+
extractor-api-lib
|
|
5
|
+
|
|
6
|
+
No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
|
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 io
|
|
16
|
+
import json
|
|
17
|
+
import re
|
|
18
|
+
import ssl
|
|
19
|
+
|
|
20
|
+
import urllib3
|
|
21
|
+
|
|
22
|
+
from admin_api_lib.extractor_api_client.openapi_client.exceptions import ApiException, ApiValueError
|
|
23
|
+
|
|
24
|
+
SUPPORTED_SOCKS_PROXIES = {"socks5", "socks5h", "socks4", "socks4a"}
|
|
25
|
+
RESTResponseType = urllib3.HTTPResponse
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def is_socks_proxy_url(url):
|
|
29
|
+
if url is None:
|
|
30
|
+
return False
|
|
31
|
+
split_section = url.split("://")
|
|
32
|
+
if len(split_section) < 2:
|
|
33
|
+
return False
|
|
34
|
+
else:
|
|
35
|
+
return split_section[0].lower() in SUPPORTED_SOCKS_PROXIES
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class RESTResponse(io.IOBase):
|
|
39
|
+
|
|
40
|
+
def __init__(self, resp) -> None:
|
|
41
|
+
self.response = resp
|
|
42
|
+
self.status = resp.status
|
|
43
|
+
self.reason = resp.reason
|
|
44
|
+
self.data = None
|
|
45
|
+
|
|
46
|
+
def read(self):
|
|
47
|
+
if self.data is None:
|
|
48
|
+
self.data = self.response.data
|
|
49
|
+
return self.data
|
|
50
|
+
|
|
51
|
+
def getheaders(self):
|
|
52
|
+
"""Returns a dictionary of the response headers."""
|
|
53
|
+
return self.response.headers
|
|
54
|
+
|
|
55
|
+
def getheader(self, name, default=None):
|
|
56
|
+
"""Returns a given response header."""
|
|
57
|
+
return self.response.headers.get(name, default)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
class RESTClientObject:
|
|
61
|
+
|
|
62
|
+
def __init__(self, configuration) -> None:
|
|
63
|
+
# urllib3.PoolManager will pass all kw parameters to connectionpool
|
|
64
|
+
# https://github.com/shazow/urllib3/blob/f9409436f83aeb79fbaf090181cd81b784f1b8ce/urllib3/poolmanager.py#L75 # noqa: E501
|
|
65
|
+
# https://github.com/shazow/urllib3/blob/f9409436f83aeb79fbaf090181cd81b784f1b8ce/urllib3/connectionpool.py#L680 # noqa: E501
|
|
66
|
+
# Custom SSL certificates and client certificates: http://urllib3.readthedocs.io/en/latest/advanced-usage.html # noqa: E501
|
|
67
|
+
|
|
68
|
+
# cert_reqs
|
|
69
|
+
if configuration.verify_ssl:
|
|
70
|
+
cert_reqs = ssl.CERT_REQUIRED
|
|
71
|
+
else:
|
|
72
|
+
cert_reqs = ssl.CERT_NONE
|
|
73
|
+
|
|
74
|
+
pool_args = {
|
|
75
|
+
"cert_reqs": cert_reqs,
|
|
76
|
+
"ca_certs": configuration.ssl_ca_cert,
|
|
77
|
+
"cert_file": configuration.cert_file,
|
|
78
|
+
"key_file": configuration.key_file,
|
|
79
|
+
}
|
|
80
|
+
if configuration.assert_hostname is not None:
|
|
81
|
+
pool_args["assert_hostname"] = configuration.assert_hostname
|
|
82
|
+
|
|
83
|
+
if configuration.retries is not None:
|
|
84
|
+
pool_args["retries"] = configuration.retries
|
|
85
|
+
|
|
86
|
+
if configuration.tls_server_name:
|
|
87
|
+
pool_args["server_hostname"] = configuration.tls_server_name
|
|
88
|
+
|
|
89
|
+
if configuration.socket_options is not None:
|
|
90
|
+
pool_args["socket_options"] = configuration.socket_options
|
|
91
|
+
|
|
92
|
+
if configuration.connection_pool_maxsize is not None:
|
|
93
|
+
pool_args["maxsize"] = configuration.connection_pool_maxsize
|
|
94
|
+
|
|
95
|
+
# https pool manager
|
|
96
|
+
self.pool_manager: urllib3.PoolManager
|
|
97
|
+
|
|
98
|
+
if configuration.proxy:
|
|
99
|
+
if is_socks_proxy_url(configuration.proxy):
|
|
100
|
+
from urllib3.contrib.socks import SOCKSProxyManager
|
|
101
|
+
|
|
102
|
+
pool_args["proxy_url"] = configuration.proxy
|
|
103
|
+
pool_args["headers"] = configuration.proxy_headers
|
|
104
|
+
self.pool_manager = SOCKSProxyManager(**pool_args)
|
|
105
|
+
else:
|
|
106
|
+
pool_args["proxy_url"] = configuration.proxy
|
|
107
|
+
pool_args["proxy_headers"] = configuration.proxy_headers
|
|
108
|
+
self.pool_manager = urllib3.ProxyManager(**pool_args)
|
|
109
|
+
else:
|
|
110
|
+
self.pool_manager = urllib3.PoolManager(**pool_args)
|
|
111
|
+
|
|
112
|
+
def request(self, method, url, headers=None, body=None, post_params=None, _request_timeout=None):
|
|
113
|
+
"""Perform requests.
|
|
114
|
+
|
|
115
|
+
:param method: http request method
|
|
116
|
+
:param url: http request url
|
|
117
|
+
:param headers: http request headers
|
|
118
|
+
:param body: request json body, for `application/json`
|
|
119
|
+
:param post_params: request post parameters,
|
|
120
|
+
`application/x-www-form-urlencoded`
|
|
121
|
+
and `multipart/form-data`
|
|
122
|
+
:param _request_timeout: timeout setting for this request. If one
|
|
123
|
+
number provided, it will be total request
|
|
124
|
+
timeout. It can also be a pair (tuple) of
|
|
125
|
+
(connection, read) timeouts.
|
|
126
|
+
"""
|
|
127
|
+
method = method.upper()
|
|
128
|
+
assert method in ["GET", "HEAD", "DELETE", "POST", "PUT", "PATCH", "OPTIONS"]
|
|
129
|
+
|
|
130
|
+
if post_params and body:
|
|
131
|
+
raise ApiValueError("body parameter cannot be used with post_params parameter.")
|
|
132
|
+
|
|
133
|
+
post_params = post_params or {}
|
|
134
|
+
headers = headers or {}
|
|
135
|
+
|
|
136
|
+
timeout = None
|
|
137
|
+
if _request_timeout:
|
|
138
|
+
if isinstance(_request_timeout, (int, float)):
|
|
139
|
+
timeout = urllib3.Timeout(total=_request_timeout)
|
|
140
|
+
elif isinstance(_request_timeout, tuple) and len(_request_timeout) == 2:
|
|
141
|
+
timeout = urllib3.Timeout(connect=_request_timeout[0], read=_request_timeout[1])
|
|
142
|
+
|
|
143
|
+
try:
|
|
144
|
+
# For `POST`, `PUT`, `PATCH`, `OPTIONS`, `DELETE`
|
|
145
|
+
if method in ["POST", "PUT", "PATCH", "OPTIONS", "DELETE"]:
|
|
146
|
+
|
|
147
|
+
# no content type provided or payload is json
|
|
148
|
+
content_type = headers.get("Content-Type")
|
|
149
|
+
if not content_type or re.search("json", content_type, re.IGNORECASE):
|
|
150
|
+
request_body = None
|
|
151
|
+
if body is not None:
|
|
152
|
+
request_body = json.dumps(body)
|
|
153
|
+
r = self.pool_manager.request(
|
|
154
|
+
method, url, body=request_body, timeout=timeout, headers=headers, preload_content=False
|
|
155
|
+
)
|
|
156
|
+
elif content_type == "application/x-www-form-urlencoded":
|
|
157
|
+
r = self.pool_manager.request(
|
|
158
|
+
method,
|
|
159
|
+
url,
|
|
160
|
+
fields=post_params,
|
|
161
|
+
encode_multipart=False,
|
|
162
|
+
timeout=timeout,
|
|
163
|
+
headers=headers,
|
|
164
|
+
preload_content=False,
|
|
165
|
+
)
|
|
166
|
+
elif content_type == "multipart/form-data":
|
|
167
|
+
# must del headers['Content-Type'], or the correct
|
|
168
|
+
# Content-Type which generated by urllib3 will be
|
|
169
|
+
# overwritten.
|
|
170
|
+
del headers["Content-Type"]
|
|
171
|
+
# Ensures that dict objects are serialized
|
|
172
|
+
post_params = [(a, json.dumps(b)) if isinstance(b, dict) else (a, b) for a, b in post_params]
|
|
173
|
+
r = self.pool_manager.request(
|
|
174
|
+
method,
|
|
175
|
+
url,
|
|
176
|
+
fields=post_params,
|
|
177
|
+
encode_multipart=True,
|
|
178
|
+
timeout=timeout,
|
|
179
|
+
headers=headers,
|
|
180
|
+
preload_content=False,
|
|
181
|
+
)
|
|
182
|
+
# Pass a `string` parameter directly in the body to support
|
|
183
|
+
# other content types than JSON when `body` argument is
|
|
184
|
+
# provided in serialized form.
|
|
185
|
+
elif isinstance(body, str) or isinstance(body, bytes):
|
|
186
|
+
r = self.pool_manager.request(
|
|
187
|
+
method, url, body=body, timeout=timeout, headers=headers, preload_content=False
|
|
188
|
+
)
|
|
189
|
+
elif headers["Content-Type"].startswith("text/") and isinstance(body, bool):
|
|
190
|
+
request_body = "true" if body else "false"
|
|
191
|
+
r = self.pool_manager.request(
|
|
192
|
+
method, url, body=request_body, preload_content=False, timeout=timeout, headers=headers
|
|
193
|
+
)
|
|
194
|
+
else:
|
|
195
|
+
# Cannot generate the request from given parameters
|
|
196
|
+
msg = """Cannot prepare a request message for provided
|
|
197
|
+
arguments. Please check that your arguments match
|
|
198
|
+
declared content type."""
|
|
199
|
+
raise ApiException(status=0, reason=msg)
|
|
200
|
+
# For `GET`, `HEAD`
|
|
201
|
+
else:
|
|
202
|
+
r = self.pool_manager.request(
|
|
203
|
+
method, url, fields={}, timeout=timeout, headers=headers, preload_content=False
|
|
204
|
+
)
|
|
205
|
+
except urllib3.exceptions.SSLError as e:
|
|
206
|
+
msg = "\n".join([type(e).__name__, str(e)])
|
|
207
|
+
raise ApiException(status=0, reason=msg)
|
|
208
|
+
|
|
209
|
+
return RESTResponse(r)
|
|
File without changes
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
|
|
3
|
+
"""
|
|
4
|
+
extractor-api-lib
|
|
5
|
+
|
|
6
|
+
No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
|
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 unittest
|
|
16
|
+
|
|
17
|
+
from admin_api_lib.extractor_api_client.openapi_client.models.content_type import ContentType
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class TestContentType(unittest.TestCase):
|
|
21
|
+
"""ContentType unit test stubs"""
|
|
22
|
+
|
|
23
|
+
def setUp(self):
|
|
24
|
+
pass
|
|
25
|
+
|
|
26
|
+
def tearDown(self):
|
|
27
|
+
pass
|
|
28
|
+
|
|
29
|
+
def testContentType(self):
|
|
30
|
+
"""Test ContentType"""
|
|
31
|
+
# inst = ContentType()
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
if __name__ == "__main__":
|
|
35
|
+
unittest.main()
|