Skip to content

Commit 5d4bba5

Browse files
committed
update config model usage
1 parent 63b16d5 commit 5d4bba5

File tree

5 files changed

+38
-72
lines changed

5 files changed

+38
-72
lines changed

lib/idp_common_pkg/idp_common/assessment/__init__.py

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@
77
This module provides services for assessing the confidence and accuracy of
88
extraction results by analyzing them against source documents using LLMs.
99
10-
The module supports both:
11-
1. Original approach: Single inference for all attributes in a section
12-
2. Granular approach: Multiple focused inferences with caching and parallelization
10+
All assessment now uses the granular approach with Strands agents for
11+
multiple focused inferences with caching and parallelization.
1312
"""
1413

1514
import logging
@@ -19,33 +18,32 @@
1918

2019
from .granular_service import GranularAssessmentService
2120
from .models import AssessmentResult, AttributeAssessment
22-
from .service import AssessmentService as OriginalAssessmentService
2321

2422
logger = logging.getLogger(__name__)
2523

2624

2725
class AssessmentService:
2826
"""
29-
Backward-compatible AssessmentService that automatically selects the appropriate implementation.
27+
Assessment service for evaluating document extraction confidence.
3028
31-
This class maintains the same interface as the original AssessmentService but automatically
32-
chooses between the original and granular implementations based on configuration.
29+
This class uses the granular Strands-based assessment approach for all assessments.
30+
It provides backward compatibility by maintaining the same interface.
3331
"""
3432

3533
def __init__(self, region: str | None = None, config: IDPConfig | None = None):
3634
"""
37-
Initialize the assessment service with automatic implementation selection.
35+
Initialize the assessment service.
3836
3937
Args:
4038
region: AWS region for Bedrock
41-
config: Configuration dictionary
39+
config: Configuration dictionary or IDPConfig model
4240
"""
4341
if config is None:
4442
config = IDPConfig()
4543
elif isinstance(config, dict):
4644
config = IDPConfig(**config)
4745

48-
self._service = create_assessment_service(region=region, config=config)
46+
self._service = GranularAssessmentService(region=region, config=config)
4947

5048
def process_document_section(self, document, section_id: str):
5149
"""Process a single section from a Document object to assess extraction confidence."""
@@ -60,40 +58,25 @@ def create_assessment_service(
6058
region: Optional[str] = None, config: Optional[IDPConfig] = None
6159
):
6260
"""
63-
Factory function to create the appropriate assessment service based on configuration.
61+
Factory function to create the assessment service.
6462
6563
Args:
6664
region: AWS region for Bedrock
67-
config: Configuration dictionary
65+
config: Configuration dictionary or IDPConfig model
6866
6967
Returns:
70-
OriginalAssessmentService or GranularAssessmentService based on configuration
68+
GranularAssessmentService instance
7169
"""
7270
if not config:
7371
config = IDPConfig()
74-
logger.info("No config provided, using original AssessmentService")
75-
return OriginalAssessmentService(region=region, config=config)
7672

77-
# Check if granular assessment is enabled (default: False for backward compatibility)
78-
79-
# Normalize the enabled value to handle both boolean and string values
80-
81-
logger.info(
82-
f"Granular assessment enabled check: raw_value={config.assessment.granular.enabled} (type: {type(config.assessment.granular.enabled)})"
83-
)
84-
85-
if config.assessment.granular.enabled:
86-
logger.info("Granular assessment enabled, using GranularAssessmentService")
87-
return GranularAssessmentService(region=region, config=config)
88-
else:
89-
logger.info("Using original AssessmentService")
90-
return OriginalAssessmentService(region=region, config=config)
73+
logger.info("Creating GranularAssessmentService (Strands-based assessment)")
74+
return GranularAssessmentService(region=region, config=config)
9175

9276

9377
__all__ = [
9478
"AssessmentService",
9579
"GranularAssessmentService",
96-
"OriginalAssessmentService",
9780
"AssessmentResult",
9881
"AttributeAssessment",
9982
"create_assessment_service",

lib/idp_common_pkg/tests/unit/config/test_config_models.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -142,23 +142,18 @@ def process_config(config: ExtractionConfig) -> bool:
142142
result = process_config(config)
143143
assert result is True
144144

145-
def test_assessment_granular_config(self):
146-
"""Test granular assessment configuration"""
145+
def test_assessment_config(self):
146+
"""Test assessment configuration with new flat structure"""
147147
config_dict = {
148148
"model": "us.amazon.nova-lite-v1:0",
149-
"granular": {
150-
"enabled": True,
151-
"list_batch_size": "5",
152-
"simple_batch_size": "10",
153-
"max_workers": "20",
154-
},
149+
"enabled": True,
150+
"max_workers": "20",
155151
}
156152
config = AssessmentConfig.model_validate(config_dict)
157153

158-
assert config.granular.enabled is True
159-
assert config.granular.list_batch_size == 5
160-
assert config.granular.simple_batch_size == 10
161-
assert config.granular.max_workers == 20
154+
assert config.enabled is True
155+
assert config.max_workers == 20
156+
assert isinstance(config.max_workers, int)
162157

163158
def test_config_validation_range_checks(self):
164159
"""Test that validation enforces ranges"""

lib/idp_common_pkg/tests/unit/config/test_config_models_integration.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -217,12 +217,10 @@ def test_criteria_validation_config(self, config_root):
217217
assert config.assessment is not None
218218
assert isinstance(config.assessment.enabled, bool)
219219

220-
# Validate granular assessment settings
221-
if hasattr(config.assessment, "granular"):
222-
assert isinstance(config.assessment.granular.enabled, bool)
223-
if config.assessment.granular.enabled:
224-
assert config.assessment.granular.list_batch_size > 0
225-
assert config.assessment.granular.simple_batch_size > 0
220+
# Validate assessment settings
221+
assert isinstance(config.assessment.enabled, bool)
222+
if config.assessment.enabled:
223+
assert config.assessment.max_workers > 0
226224

227225
def test_config_with_all_optional_fields(self, config_root):
228226
"""Test that configs work even if optional fields are missing"""
@@ -284,8 +282,8 @@ def test_config_type_coercion(self):
284282
assert config.extraction.top_p == 0.2
285283
assert isinstance(config.extraction.top_p, float)
286284

287-
assert config.assessment.granular.list_batch_size == 5
288-
assert isinstance(config.assessment.granular.list_batch_size, int)
285+
assert config.assessment.max_workers == 20
286+
assert isinstance(config.assessment.max_workers, int)
289287

290288
def test_boolean_variations(self):
291289
"""Test various boolean representations"""

patterns/pattern-2/src/assessment_function/index.py

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -151,13 +151,9 @@ def handler(event, context):
151151
if not section:
152152
raise ValueError(f"Section {section_id} not found in document")
153153

154-
# Check if granular assessment is enabled (moved earlier for Lambda metering context)
155-
assessment_context = (
156-
"GranularAssessment" if config.assessment.granular.enabled else "Assessment"
157-
)
158-
logger.info(
159-
f"Assessment mode: {'Granular' if config.assessment.granular.enabled else 'Regular'} (context: {assessment_context})"
160-
)
154+
# Assessment context for Lambda metering
155+
assessment_context = "Assessment"
156+
logger.info(f"Assessment mode: Strands-based (context: {assessment_context})")
161157

162158
# Intelligent Assessment Skip: Check if extraction results already contain explainability_info
163159
if section.extraction_result_uri and section.extraction_result_uri.strip():
@@ -254,15 +250,13 @@ def handler(event, context):
254250
# Initialize assessment service with cache table for enhanced retry handling
255251
cache_table = os.environ.get("TRACKING_TABLE")
256252

257-
# Check if granular assessment is enabled
258-
259-
# Use granular assessment service (always enabled)
253+
# Use Strands-based granular assessment service (always enabled)
260254
from idp_common.assessment.granular_service import GranularAssessmentService
261255

262256
assessment_service = GranularAssessmentService(
263257
config=config, cache_table=cache_table
264258
)
265-
logger.info("Using granular assessment service")
259+
logger.info("Using Strands-based assessment service")
266260

267261
# Process the document section for assessment
268262
t0 = time.time()
@@ -333,11 +327,11 @@ def handler(event, context):
333327

334328
# Assessment validation
335329
validation_enabled = (
336-
config.assessment.granular.enabled and config.assessment.validation_enabled
330+
config.assessment.enabled and config.assessment.validation_enabled
337331
)
338-
logger.info(f"Assessment Enabled:{config.assessment.granular.enabled}")
339-
logger.info(f"Validation Enabled:{validation_enabled}")
340-
if not config.assessment.granular.enabled:
332+
logger.info(f"Assessment Enabled: {config.assessment.enabled}")
333+
logger.info(f"Validation Enabled: {validation_enabled}")
334+
if not config.assessment.enabled:
341335
logger.info("Assessment is disabled.")
342336
elif not validation_enabled:
343337
logger.info("Assessment validation is disabled.")

patterns/pattern-3/src/assessment_function/index.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,9 @@ def handler(event, context):
6363
if not section:
6464
raise ValueError(f"Section {section_id} not found in document")
6565

66-
# Check if granular assessment is enabled (for Lambda metering context)
67-
granular_config = config.assessment.granular
68-
granular_enabled = granular_config.enabled
69-
assessment_context = "GranularAssessment" if granular_enabled else "Assessment"
70-
logger.info(
71-
f"Assessment mode: {'Granular' if granular_enabled else 'Regular'} (context: {assessment_context})"
72-
)
66+
# Assessment context for Lambda metering
67+
assessment_context = "Assessment"
68+
logger.info(f"Assessment mode: Strands-based (context: {assessment_context})")
7369

7470
# Intelligent Assessment Skip: Check if extraction results already contain explainability_info
7571
if section.extraction_result_uri and section.extraction_result_uri.strip():

0 commit comments

Comments
 (0)