Skip to content

Commit 43b7980

Browse files
author
anna-singleton-resolver
committed
feat: correlationid can be specified on ImageData
1 parent 26c8819 commit 43b7980

3 files changed

Lines changed: 19 additions & 14 deletions

File tree

src/resolver_athena_client/client/athena_client.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ async def image_stream():
121121
yield response
122122

123123
async def classify_single(
124-
self, image_data: ImageData, correlation_id: str | None = None
124+
self, image_data: ImageData
125125
) -> ClassificationOutput:
126126
"""Classify a single image synchronously without deployment context.
127127
@@ -169,9 +169,6 @@ async def classify_single(
169169
f"Weight: {classification.weight}")
170170
171171
"""
172-
if correlation_id is None:
173-
correlation_id = str(uuid.uuid4())
174-
175172
processed_image = image_data
176173

177174
# Apply image resizing if enabled
@@ -196,7 +193,7 @@ async def classify_single(
196193

197194
classification_input = ClassificationInput(
198195
affiliate=self.options.affiliate,
199-
correlation_id=correlation_id,
196+
correlation_id=processed_image.correlation_id or str(uuid.uuid4()),
200197
encoding=request_encoding,
201198
data=processed_image.data,
202199
format=image_format,
@@ -257,19 +254,24 @@ async def transform_image(image_data: ImageData) -> ClassificationInput:
257254
else RequestEncoding.REQUEST_ENCODING_UNCOMPRESSED
258255
)
259256

260-
# Create classification input directly
261-
correlation_provider = self.options.correlation_provider()
262257

263258
# Ensure we never send UNSPECIFIED format over the API
264259
image_format = compressed_image.image_format
265260
if image_format == ImageFormat.IMAGE_FORMAT_UNSPECIFIED:
266261
image_format = ImageFormat.IMAGE_FORMAT_RAW_UINT8_BGR
267262

263+
if compressed_image.correlation_id:
264+
correlation_id = compressed_image.correlation_id
265+
else:
266+
# Create classification input directly
267+
correlation_provider = self.options.correlation_provider()
268+
correlation_id = correlation_provider.get_correlation_id(
269+
compressed_image.data
270+
)
271+
268272
return ClassificationInput(
269273
affiliate=self.options.affiliate,
270-
correlation_id=correlation_provider.get_correlation_id(
271-
compressed_image.data
272-
),
274+
correlation_id=correlation_id,
273275
data=compressed_image.data,
274276
encoding=request_encoding,
275277
format=image_format,

src/resolver_athena_client/client/models/input_model.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,14 @@ async def image_stream():
6767
6868
"""
6969

70-
def __init__(self, image_bytes: bytes) -> None:
70+
def __init__(self, image_bytes: bytes, correlation_id: None | str = None) -> None:
7171
"""Initialize ImageData with bytes and calculate hashes.
7272
7373
Args:
7474
----
7575
image_bytes: The raw bytes of the image.
76+
correlation_id: Optional correlation ID to associate with this
77+
image data, if not provided, it will be generated by the client.
7678
7779
"""
7880
self.data: bytes = image_bytes
@@ -83,6 +85,7 @@ def __init__(self, image_bytes: bytes) -> None:
8385
hashlib.sha256(image_bytes).hexdigest()
8486
]
8587
self.md5_hashes: list[str] = [hashlib.md5(image_bytes).hexdigest()]
88+
self.correlation_id: None | str = correlation_id
8689

8790
def add_transformation_hashes(self) -> None:
8891
"""Add new hashes for the current data to track transformations.

tests/test_classify_single.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,10 @@ async def test_classify_single_with_correlation_id(
122122
return_value=mock_output
123123
)
124124

125+
copied_image_data = ImageData(sample_image_data.data, correlation_id=custom_correlation_id)
126+
125127
# Call classify_single with custom correlation ID
126-
_ = await athena_client.classify_single(
127-
sample_image_data, correlation_id=custom_correlation_id
128-
)
128+
_ = await athena_client.classify_single(copied_image_data)
129129

130130
# Verify correlation ID was used
131131
call_args = athena_client.classifier.classify_single.call_args[0][0]

0 commit comments

Comments
 (0)