my-aws-helpers 5.2.0__tar.gz → 5.4.0__tar.gz

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.

Potentially problematic release.


This version of my-aws-helpers might be problematic. Click here for more details.

Files changed (28) hide show
  1. {my_aws_helpers-5.2.0 → my_aws_helpers-5.4.0}/PKG-INFO +1 -1
  2. {my_aws_helpers-5.2.0 → my_aws_helpers-5.4.0}/my_aws_helpers/bedrock.py +55 -2
  3. {my_aws_helpers-5.2.0 → my_aws_helpers-5.4.0}/my_aws_helpers.egg-info/PKG-INFO +1 -1
  4. {my_aws_helpers-5.2.0 → my_aws_helpers-5.4.0}/setup.py +1 -1
  5. {my_aws_helpers-5.2.0 → my_aws_helpers-5.4.0}/MANIFEST.in +0 -0
  6. {my_aws_helpers-5.2.0 → my_aws_helpers-5.4.0}/README.md +0 -0
  7. {my_aws_helpers-5.2.0 → my_aws_helpers-5.4.0}/my_aws_helpers/api.py +0 -0
  8. {my_aws_helpers-5.2.0 → my_aws_helpers-5.4.0}/my_aws_helpers/auth.py +0 -0
  9. {my_aws_helpers-5.2.0 → my_aws_helpers-5.4.0}/my_aws_helpers/cognito.py +0 -0
  10. {my_aws_helpers-5.2.0 → my_aws_helpers-5.4.0}/my_aws_helpers/dynamo.py +0 -0
  11. {my_aws_helpers-5.2.0 → my_aws_helpers-5.4.0}/my_aws_helpers/errors.py +0 -0
  12. {my_aws_helpers-5.2.0 → my_aws_helpers-5.4.0}/my_aws_helpers/event.py +0 -0
  13. {my_aws_helpers-5.2.0 → my_aws_helpers-5.4.0}/my_aws_helpers/logging.py +0 -0
  14. {my_aws_helpers-5.2.0 → my_aws_helpers-5.4.0}/my_aws_helpers/prompts/__init__.py +0 -0
  15. {my_aws_helpers-5.2.0 → my_aws_helpers-5.4.0}/my_aws_helpers/prompts/markdown_system_prompt.txt +0 -0
  16. {my_aws_helpers-5.2.0 → my_aws_helpers-5.4.0}/my_aws_helpers/prompts/transactions_headers_prompt.txt +0 -0
  17. {my_aws_helpers-5.2.0 → my_aws_helpers-5.4.0}/my_aws_helpers/prompts/transactions_headers_prompt_v2.txt +0 -0
  18. {my_aws_helpers-5.2.0 → my_aws_helpers-5.4.0}/my_aws_helpers/prompts/transactions_prompt.txt +0 -0
  19. {my_aws_helpers-5.2.0 → my_aws_helpers-5.4.0}/my_aws_helpers/s3.py +0 -0
  20. {my_aws_helpers-5.2.0 → my_aws_helpers-5.4.0}/my_aws_helpers/sfn.py +0 -0
  21. {my_aws_helpers-5.2.0 → my_aws_helpers-5.4.0}/my_aws_helpers.egg-info/SOURCES.txt +0 -0
  22. {my_aws_helpers-5.2.0 → my_aws_helpers-5.4.0}/my_aws_helpers.egg-info/dependency_links.txt +0 -0
  23. {my_aws_helpers-5.2.0 → my_aws_helpers-5.4.0}/my_aws_helpers.egg-info/requires.txt +0 -0
  24. {my_aws_helpers-5.2.0 → my_aws_helpers-5.4.0}/my_aws_helpers.egg-info/top_level.txt +0 -0
  25. {my_aws_helpers-5.2.0 → my_aws_helpers-5.4.0}/my_aws_helpers.egg-info/zip-safe +0 -0
  26. {my_aws_helpers-5.2.0 → my_aws_helpers-5.4.0}/setup.cfg +0 -0
  27. {my_aws_helpers-5.2.0 → my_aws_helpers-5.4.0}/tests/test_cognito.py +0 -0
  28. {my_aws_helpers-5.2.0 → my_aws_helpers-5.4.0}/tests/test_event.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: my_aws_helpers
3
- Version: 5.2.0
3
+ Version: 5.4.0
4
4
  Summary: AWS Helpers
5
5
  Home-page: https://github.com/JarrodMccarthy/aws_helpers.git
6
6
  Author: Jarrod McCarthy
@@ -11,7 +11,12 @@ from enum import Enum
11
11
  import pymupdf
12
12
  import concurrent.futures
13
13
  from dataclasses import dataclass
14
- from my_aws_helpers.s3 import S3Serialiser
14
+ from my_aws_helpers.s3 import S3Serialiser, BaseS3Object, BaseS3Queries, S3, S3Location
15
+
16
+ from my_aws_helpers.logging import select_powertools_logger
17
+
18
+
19
+ logger = select_powertools_logger("aws-helpers-bedrock")
15
20
 
16
21
 
17
22
  class ImageType(str, Enum):
@@ -44,7 +49,7 @@ class TokenUsage:
44
49
 
45
50
 
46
51
  @dataclass
47
- class OCRResult:
52
+ class OCRResult(BaseS3Object):
48
53
  content: List[Dict[str, str]]
49
54
  token_usage: TokenUsage
50
55
  page_number: int
@@ -59,12 +64,60 @@ class OCRResult:
59
64
 
60
65
  @classmethod
61
66
  def from_s3_representation(cls, obj: dict) -> OCRResult:
67
+ obj['token_usage'] = TokenUsage.from_dict(obj.get("token_usage", {})),
62
68
  return cls(**obj)
63
69
 
64
70
  def to_s3_representation(self) -> dict:
65
71
  obj = copy(vars(self))
72
+ obj['token_usage'] = S3Serialiser.object_serialiser(obj=obj['token_usage'])
66
73
  return S3Serialiser.object_serialiser(obj=obj)
67
74
 
75
+ def get_save_location(self, bucket_name: str) -> S3Location:
76
+ pass
77
+
78
+
79
+ class OCRResultQueries(BaseS3Queries):
80
+ def __init__(self, s3_client: S3, bucket_name: str):
81
+ super().__init__(s3_client=s3_client, bucket_name=bucket_name)
82
+
83
+ def save_ocr_result_to_s3(
84
+ self, ocr_result: OCRResult, save_location: S3Location
85
+ ) -> Optional[S3Location]:
86
+ try:
87
+ obj = ocr_result.to_s3_representation()
88
+ return self.s3_client.save_dict_to_s3(
89
+ content=obj,
90
+ s3_location=save_location,
91
+ )
92
+ except Exception as e:
93
+ logger.exception(f"Failed to save ocr result to s3 due to {e}")
94
+ return None
95
+
96
+ def _concurrent_s3_read(
97
+ self, locations: List[S3Location], max_workers: int = 10
98
+ ) -> List[OCRResult]:
99
+ results: List[OCRResult] = list()
100
+ futures = list()
101
+ with concurrent.futures.ThreadPoolExecutor(max_workers=max_workers) as executor:
102
+ for loc in locations:
103
+ future = executor.submit(
104
+ self.s3_client.read_dict_from_s3,
105
+ s3_location=loc,
106
+ )
107
+ futures.append(future)
108
+ for f in futures:
109
+ results.append(f.result())
110
+ results = [r for r in results if r is not None]
111
+ return results
112
+
113
+ def get_listing_by_key_prefix(self, prefix: str) -> List[OCRResult]:
114
+ locations = self.s3_client.list_objects_by_prefix(
115
+ bucket_name=self.bucket_name, prefix=prefix
116
+ )
117
+ objects = self._concurrent_s3_read(listing_locations=locations)
118
+ ocr_results = [OCRResult.from_s3_representation(obj=obj) for obj in objects]
119
+ return ocr_results
120
+
68
121
 
69
122
  class Bedrock:
70
123
  def __init__(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: my-aws-helpers
3
- Version: 5.2.0
3
+ Version: 5.4.0
4
4
  Summary: AWS Helpers
5
5
  Home-page: https://github.com/JarrodMccarthy/aws_helpers.git
6
6
  Author: Jarrod McCarthy
@@ -3,7 +3,7 @@ from setuptools import find_namespace_packages, setup
3
3
 
4
4
  base_path = os.path.abspath(os.path.dirname(__file__))
5
5
 
6
- version = "5.2.0"
6
+ version = "5.4.0"
7
7
 
8
8
  core = [
9
9
  "boto3==1.34.36",
File without changes
File without changes