Skip to content

Commit f40a1c4

Browse files
committed
Merge branch 'fix/discovery-config-setup' into 'develop'
Fix tests, remove nonexistant child class methods See merge request genaiic-reusable-assets/engagement-artifacts/genaiic-idp-accelerator!395
2 parents 591e8a1 + 4b83473 commit f40a1c4

File tree

5 files changed

+50
-49
lines changed

5 files changed

+50
-49
lines changed

lib/idp_common_pkg/idp_common/assessment/__init__.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,19 @@ class AssessmentService:
3232
chooses between the original and granular implementations based on configuration.
3333
"""
3434

35-
def __init__(self, region: str = None, config: IDPConfig = None):
35+
def __init__(self, region: str | None = None, config: IDPConfig | None = None):
3636
"""
3737
Initialize the assessment service with automatic implementation selection.
3838
3939
Args:
4040
region: AWS region for Bedrock
4141
config: Configuration dictionary
4242
"""
43+
if config is None:
44+
config = IDPConfig()
45+
elif isinstance(config, dict):
46+
config = IDPConfig(**config)
47+
4348
self._service = create_assessment_service(region=region, config=config)
4449

4550
def process_document_section(self, document, section_id: str):
@@ -50,15 +55,6 @@ def assess_document(self, document):
5055
"""Assess extraction confidence for all sections in a document."""
5156
return self._service.assess_document(document)
5257

53-
# Expose internal methods for compatibility
54-
def _get_class_attributes(self, class_label: str):
55-
"""Get attributes for a specific document class from configuration."""
56-
return self._service._get_class_attributes(class_label)
57-
58-
def _format_attribute_descriptions(self, attributes):
59-
"""Format attribute descriptions for the prompt."""
60-
return self._service._format_attribute_descriptions(attributes)
61-
6258

6359
def create_assessment_service(
6460
region: Optional[str] = None, config: Optional[IDPConfig] = None

lib/idp_common_pkg/idp_common/assessment/granular_service.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import time
1818
from concurrent.futures import ThreadPoolExecutor, as_completed
1919
from dataclasses import dataclass
20-
from typing import Any, Dict, Generator, List, Optional, Tuple, Union
20+
from typing import Any, Dict, Generator, List, Optional, Tuple
2121

2222
from idp_common import bedrock, image, metrics, s3, utils
2323
from idp_common.config.models import IDPConfig
@@ -107,9 +107,9 @@ class GranularAssessmentService:
107107

108108
def __init__(
109109
self,
110-
region: str = None,
111-
config: Union[Dict[str, Any], IDPConfig] = None,
112-
cache_table: str = None,
110+
region: str | None = None,
111+
config: Dict[str, Any] | IDPConfig | None = None,
112+
cache_table: str | None = None,
113113
):
114114
"""
115115
Initialize the granular assessment service.

lib/idp_common_pkg/idp_common/assessment/service.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ class AssessmentService:
8282
"""Service for assessing extraction result confidence using LLMs."""
8383

8484
def __init__(
85-
self, region: str = None, config: Union[Dict[str, Any], IDPConfig] = None
85+
self,
86+
region: str | None = None,
87+
config: Union[Dict[str, Any], IDPConfig, None] = None,
8688
):
8789
"""
8890
Initialize the assessment service.
@@ -94,10 +96,12 @@ def __init__(
9496
# Convert dict to IDPConfig if needed
9597
if config is not None and isinstance(config, dict):
9698
config_model: IDPConfig = IDPConfig(**config)
97-
elif config is None:
99+
100+
if not isinstance(config, IDPConfig) and config is not None:
101+
config_model = IDPConfig(**config)
102+
103+
if config is None:
98104
config_model = IDPConfig()
99-
else:
100-
config_model = config
101105

102106
self.config = config_model
103107
self.region = region or os.environ.get("AWS_REGION")

lib/idp_common_pkg/tests/unit/discovery/test_classes_discovery.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,8 @@ def mock_ground_truth_data(self):
105105
@pytest.fixture
106106
def mock_configuration_item(self):
107107
"""Fixture providing a mock configuration item."""
108-
return {
109-
"Configuration": "Custom",
110-
"classes": [
108+
return IDPConfig(
109+
classes=[
111110
{
112111
"name": "W-4",
113112
"description": "Employee's Withholding Certificate form",
@@ -119,8 +118,8 @@ def mock_configuration_item(self):
119118
}
120119
],
121120
}
122-
],
123-
}
121+
]
122+
)
124123

125124
@pytest.fixture
126125
def service(self, mock_config):
@@ -693,10 +692,10 @@ def test_discovery_classes_with_document_updates_existing_class(
693692
# Get the call args - might be save_configuration or update_configuration
694693
if service.config_manager.save_configuration.called:
695694
call_args = service.config_manager.save_configuration.call_args[0]
696-
updated_classes = call_args[1]["classes"]
695+
updated_classes = call_args[1].classes
697696
else:
698697
call_args = service.config_manager.update_configuration.call_args[0]
699-
updated_classes = call_args[1]["classes"]
698+
updated_classes = call_args[1].classes
700699

701700
# Should have 2 classes (Other-Form + updated W-4)
702701
assert len(updated_classes) == 2
@@ -748,10 +747,10 @@ def test_discovery_classes_with_document_no_existing_config(self, service):
748747
# Get the call args - might be save_configuration or update_configuration
749748
if service.config_manager.save_configuration.called:
750749
call_args = service.config_manager.save_configuration.call_args[0]
751-
updated_classes = call_args[1]["classes"]
750+
updated_classes = call_args[1].classes
752751
else:
753752
call_args = service.config_manager.update_configuration.call_args[0]
754-
updated_classes = call_args[1]["classes"]
753+
updated_classes = call_args[1].classes
755754

756755
# Should have 1 class
757756
assert len(updated_classes) == 1

lib/idp_common_pkg/tests/unit/discovery/test_classes_discovery_integration.py

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
# Import application modules
1919
from idp_common.discovery.classes_discovery import ClassesDiscovery
20+
from idp_common.config.models import IDPConfig
2021

2122

2223
@pytest.mark.unit
@@ -348,27 +349,28 @@ def test_discovery_updates_existing_configuration(
348349
service_with_mocks._mock_bedrock_client.return_value = mock_w4_bedrock_response
349350

350351
# Mock existing configuration with different forms in JSON Schema format
351-
existing_item = MagicMock()
352-
existing_item.classes = [
353-
{
354-
"$schema": "http://json-schema.org/draft-07/schema#",
355-
"$id": "i9",
356-
"type": "object",
357-
"title": "I-9",
358-
"description": "Employment Eligibility Verification",
359-
"x-aws-idp-document-type": "I-9",
360-
"properties": {},
361-
},
362-
{
363-
"$schema": "http://json-schema.org/draft-07/schema#",
364-
"$id": "w4",
365-
"type": "object",
366-
"title": "W-4",
367-
"description": "Old W-4 description",
368-
"x-aws-idp-document-type": "W-4",
369-
"properties": {},
370-
},
371-
]
352+
existing_item = IDPConfig(
353+
classes=[
354+
{
355+
"$schema": "http://json-schema.org/draft-07/schema#",
356+
"$id": "i9",
357+
"type": "object",
358+
"title": "I-9",
359+
"description": "Employment Eligibility Verification",
360+
"x-aws-idp-document-type": "I-9",
361+
"properties": {},
362+
},
363+
{
364+
"$schema": "http://json-schema.org/draft-07/schema#",
365+
"$id": "w4",
366+
"type": "object",
367+
"title": "W-4",
368+
"description": "Old W-4 description",
369+
"x-aws-idp-document-type": "W-4",
370+
"properties": {},
371+
},
372+
]
373+
)
372374
# Create mocks for config_manager methods
373375
service_with_mocks.config_manager.get_configuration = MagicMock(
374376
return_value=existing_item
@@ -387,7 +389,7 @@ def test_discovery_updates_existing_configuration(
387389
save_config_args = (
388390
service_with_mocks.config_manager.save_configuration.call_args[0]
389391
)
390-
updated_classes = save_config_args[1]["classes"]
392+
updated_classes = save_config_args[1].classes
391393

392394
# Should have 2 classes: I-9 (unchanged) + W-4 (updated)
393395
assert len(updated_classes) == 2

0 commit comments

Comments
 (0)