my-aws-helpers 4.5.0__tar.gz → 4.7.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.
- {my_aws_helpers-4.5.0 → my_aws_helpers-4.7.0}/PKG-INFO +1 -1
- {my_aws_helpers-4.5.0 → my_aws_helpers-4.7.0}/my_aws_helpers/bedrock.py +34 -0
- {my_aws_helpers-4.5.0 → my_aws_helpers-4.7.0}/my_aws_helpers/s3.py +18 -3
- {my_aws_helpers-4.5.0 → my_aws_helpers-4.7.0}/my_aws_helpers.egg-info/PKG-INFO +1 -1
- {my_aws_helpers-4.5.0 → my_aws_helpers-4.7.0}/setup.py +1 -1
- {my_aws_helpers-4.5.0 → my_aws_helpers-4.7.0}/MANIFEST.in +0 -0
- {my_aws_helpers-4.5.0 → my_aws_helpers-4.7.0}/README.md +0 -0
- {my_aws_helpers-4.5.0 → my_aws_helpers-4.7.0}/my_aws_helpers/api.py +0 -0
- {my_aws_helpers-4.5.0 → my_aws_helpers-4.7.0}/my_aws_helpers/auth.py +0 -0
- {my_aws_helpers-4.5.0 → my_aws_helpers-4.7.0}/my_aws_helpers/cognito.py +0 -0
- {my_aws_helpers-4.5.0 → my_aws_helpers-4.7.0}/my_aws_helpers/dynamo.py +0 -0
- {my_aws_helpers-4.5.0 → my_aws_helpers-4.7.0}/my_aws_helpers/errors.py +0 -0
- {my_aws_helpers-4.5.0 → my_aws_helpers-4.7.0}/my_aws_helpers/event.py +0 -0
- {my_aws_helpers-4.5.0 → my_aws_helpers-4.7.0}/my_aws_helpers/logging.py +0 -0
- {my_aws_helpers-4.5.0 → my_aws_helpers-4.7.0}/my_aws_helpers/prompts/__init__.py +0 -0
- {my_aws_helpers-4.5.0 → my_aws_helpers-4.7.0}/my_aws_helpers/prompts/markdown_system_prompt.txt +0 -0
- {my_aws_helpers-4.5.0 → my_aws_helpers-4.7.0}/my_aws_helpers/prompts/transactions_headers_prompt.txt +0 -0
- {my_aws_helpers-4.5.0 → my_aws_helpers-4.7.0}/my_aws_helpers/prompts/transactions_headers_prompt_v2.txt +0 -0
- {my_aws_helpers-4.5.0 → my_aws_helpers-4.7.0}/my_aws_helpers/prompts/transactions_prompt.txt +0 -0
- {my_aws_helpers-4.5.0 → my_aws_helpers-4.7.0}/my_aws_helpers/sfn.py +0 -0
- {my_aws_helpers-4.5.0 → my_aws_helpers-4.7.0}/my_aws_helpers.egg-info/SOURCES.txt +0 -0
- {my_aws_helpers-4.5.0 → my_aws_helpers-4.7.0}/my_aws_helpers.egg-info/dependency_links.txt +0 -0
- {my_aws_helpers-4.5.0 → my_aws_helpers-4.7.0}/my_aws_helpers.egg-info/requires.txt +0 -0
- {my_aws_helpers-4.5.0 → my_aws_helpers-4.7.0}/my_aws_helpers.egg-info/top_level.txt +0 -0
- {my_aws_helpers-4.5.0 → my_aws_helpers-4.7.0}/my_aws_helpers.egg-info/zip-safe +0 -0
- {my_aws_helpers-4.5.0 → my_aws_helpers-4.7.0}/setup.cfg +0 -0
- {my_aws_helpers-4.5.0 → my_aws_helpers-4.7.0}/tests/test_cognito.py +0 -0
- {my_aws_helpers-4.5.0 → my_aws_helpers-4.7.0}/tests/test_event.py +0 -0
|
@@ -5,11 +5,13 @@ import json
|
|
|
5
5
|
import time
|
|
6
6
|
import os
|
|
7
7
|
import io
|
|
8
|
+
import base64
|
|
8
9
|
from typing import Optional, List, Dict
|
|
9
10
|
from enum import Enum
|
|
10
11
|
import pymupdf
|
|
11
12
|
import concurrent.futures
|
|
12
13
|
from dataclasses import dataclass
|
|
14
|
+
from my_aws_helpers.s3 import ContentType
|
|
13
15
|
|
|
14
16
|
|
|
15
17
|
class PromptType(str, Enum):
|
|
@@ -237,3 +239,35 @@ class Bedrock:
|
|
|
237
239
|
except Exception as e:
|
|
238
240
|
self.logger.exception(e)
|
|
239
241
|
return []
|
|
242
|
+
|
|
243
|
+
def _get_image_block(self, image: bytes, image_content_type: ContentType) -> dict:
|
|
244
|
+
return {
|
|
245
|
+
"image": {
|
|
246
|
+
"format": image_content_type,
|
|
247
|
+
"source": {
|
|
248
|
+
"bytes": image,
|
|
249
|
+
},
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
def image_analysis(
|
|
254
|
+
self, images: List[bytes], prompt: str, image_content_type: ContentType
|
|
255
|
+
) -> OCRResult:
|
|
256
|
+
|
|
257
|
+
system_prompt = [{"text": prompt}]
|
|
258
|
+
message = [
|
|
259
|
+
{
|
|
260
|
+
"role": "user",
|
|
261
|
+
"content": [self._get_image_block(image=image, image_content_type=image_content_type) for image in images],
|
|
262
|
+
}
|
|
263
|
+
]
|
|
264
|
+
response = self.client.converse(
|
|
265
|
+
modelId=self.model_id, messages=message, system=system_prompt
|
|
266
|
+
)
|
|
267
|
+
|
|
268
|
+
result = {}
|
|
269
|
+
result["content"] = json.loads(
|
|
270
|
+
response["output"]["message"]["content"][0]["text"]
|
|
271
|
+
)
|
|
272
|
+
result["token_usage"] = response["usage"]
|
|
273
|
+
return OCRResult.from_dict(data=result)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import boto3
|
|
2
2
|
import io
|
|
3
3
|
import json
|
|
4
|
-
from typing import Optional, Any, Dict
|
|
4
|
+
from typing import Optional, Any, Dict, List
|
|
5
5
|
from datetime import datetime, date
|
|
6
6
|
from copy import copy
|
|
7
7
|
import os
|
|
@@ -41,6 +41,7 @@ class S3Serialiser:
|
|
|
41
41
|
return {k: S3Serialiser.object_serialiser(v) for k, v in obj.items()}
|
|
42
42
|
return S3Serialiser._serialise(obj=obj)
|
|
43
43
|
|
|
44
|
+
|
|
44
45
|
class S3Location:
|
|
45
46
|
bucket: str
|
|
46
47
|
file_name: str
|
|
@@ -94,6 +95,18 @@ class S3:
|
|
|
94
95
|
Body=json.dumps(object), Bucket=bucket_name, Key=file_name
|
|
95
96
|
)
|
|
96
97
|
|
|
98
|
+
def list_objects_by_prefix(self, bucket_name: str, prefix: str) -> List[Dict]:
|
|
99
|
+
try:
|
|
100
|
+
response = self.client.client.list_objects_v2(
|
|
101
|
+
Bucket=bucket_name, Prefix=prefix
|
|
102
|
+
)
|
|
103
|
+
return response["Contents"]
|
|
104
|
+
except Exception as e:
|
|
105
|
+
logger.exception(
|
|
106
|
+
f"Failed to get objects from s3: {bucket_name}/{prefix} due to {e}"
|
|
107
|
+
)
|
|
108
|
+
return []
|
|
109
|
+
|
|
97
110
|
def get_object(self, bucket_name: str, file_name: str):
|
|
98
111
|
response = self.client.get_object(Bucket=bucket_name, Key=file_name)
|
|
99
112
|
return self._streaming_body_to_dict(response["Body"])
|
|
@@ -247,7 +260,9 @@ class S3:
|
|
|
247
260
|
)
|
|
248
261
|
except Exception as e:
|
|
249
262
|
logger.exception(f"Failed to save jpeg to s3 due to {e}")
|
|
250
|
-
return None
|
|
263
|
+
return None
|
|
251
264
|
|
|
252
265
|
def read_dict_from_s3(self, s3_location: S3Location) -> dict:
|
|
253
|
-
return json.loads(
|
|
266
|
+
return json.loads(
|
|
267
|
+
self.read_binary_from_s3(s3_location=s3_location).decode("utf-8")
|
|
268
|
+
)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{my_aws_helpers-4.5.0 → my_aws_helpers-4.7.0}/my_aws_helpers/prompts/markdown_system_prompt.txt
RENAMED
|
File without changes
|
{my_aws_helpers-4.5.0 → my_aws_helpers-4.7.0}/my_aws_helpers/prompts/transactions_headers_prompt.txt
RENAMED
|
File without changes
|
|
File without changes
|
{my_aws_helpers-4.5.0 → my_aws_helpers-4.7.0}/my_aws_helpers/prompts/transactions_prompt.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|