66import logging
77from typing import Tuple , Dict , Any , Optional
88
9+ from idp_common .config .models import IDPConfig
10+
911# Import yaml with fallback for systems that don't have it installed
1012try :
1113 import yaml
@@ -620,7 +622,7 @@ def extract_structured_data_from_text(text: str, preferred_format: str = 'auto')
620622 logger .warning ("Could not parse as either JSON or YAML, returning original text" )
621623 return text , 'unknown'
622624
623- def check_token_limit (document_text : str , extraction_results : Dict [str , Any ], config : Dict [ str , Any ] ) -> \
625+ def check_token_limit (document_text : str , extraction_results : Dict [str , Any ], config : IDPConfig ) -> \
624626Optional [str ]:
625627 """
626628 Create token limit warning message based on the configured value of max_tokens
@@ -634,11 +636,11 @@ def check_token_limit(document_text: str, extraction_results: Dict[str, Any], co
634636 Error message based on the configured_max_tokens, None otherwise
635637 """
636638 # Information for logging and troubleshooting
637- assessment_config = config .get ( " assessment" , {})
639+ assessment_config = config .assessment
638640 logger .info (f"assessment_config: { assessment_config } " )
639- model_id = config . get ( "model_id" ) or assessment_config . get ( "model" , " unknown")
641+ model_id = assessment_config . model or " unknown"
640642 logger .info (f"model_id: { model_id } " )
641- configured_max_tokens = assessment_config .get ( " max_tokens" )
643+ configured_max_tokens = assessment_config .max_tokens
642644 logger .info (f"configured_max_tokens: { configured_max_tokens } " )
643645 estimated_tokens = (len (document_text ) + len (str (extraction_results ))) / 4
644646 logger .info (f"Estimated tokens: { estimated_tokens } " )
0 commit comments