in tools/doc_intelligence.py [0:0]
def __init__(self):
"""
Initializes the DocumentIntelligence client.
"""
# ai service resource name
self.service_name = os.getenv('AZURE_FORMREC_SERVICE', None)
if self.service_name is None:
logging.error("[docintelligence] The environment variable 'AZURE_FORMREC_SERVICE' is not set.")
raise EnvironmentError("The environment variable 'AZURE_FORMREC_SERVICE' is not set.")
# API configuration
self.DOCINT_40_API = '2023-10-31-preview'
self.DEFAULT_API_VERSION = '2024-11-30'
self.api_version = os.getenv('FORM_REC_API_VERSION', os.getenv('DOCINT_API_VERSION', self.DEFAULT_API_VERSION))
self.docint_40_api = self.api_version >= self.DOCINT_40_API
# Network isolation
network_isolation = os.getenv('NETWORK_ISOLATION', 'false')
self.network_isolation = network_isolation.lower() == 'true'
# Supported extensions
self.file_extensions = [
"pdf",
"bmp",
"jpg",
"jpeg",
"png",
"tiff"
]
self.ai_service_type = "formrecognizer"
self.output_content_format = ""
self.docint_features = ""
self.analyze_output_options = ""
if self.docint_40_api:
self.ai_service_type = "documentintelligence"
self.file_extensions.extend(["docx", "pptx", "xlsx", "html"])
self.output_content_format = "markdown"
self.analyze_output_options = "figures"
# Initialize the ChainedTokenCredential with ManagedIdentityCredential and AzureCliCredential
try:
self.credential = ChainedTokenCredential(
ManagedIdentityCredential(),
AzureCliCredential()
)
logging.debug("[docintelligence] Initialized ChainedTokenCredential with ManagedIdentityCredential and AzureCliCredential.")
except Exception as e:
logging.error(f"[docintelligence] Failed to initialize ChainedTokenCredential: {e}")
raise