refactored and cleaned ai service chain

This commit is contained in:
ValueOn AG 2025-10-31 00:31:29 +01:00
parent 6ee07ece1e
commit 946a19b206
2 changed files with 115 additions and 160 deletions

View file

@ -1,160 +0,0 @@
```mermaid
flowchart TD
%% External/shared services/utilities
subgraph External and Shared
AiObjectsCall[AiObjects.call()];
AiObjectsGen[AiObjects.generateImage()];
ExtractionService[ExtractionService.extractContent()];
GenServicePrompt[GenerationService.getAdaptiveExtractionPrompt()];
GenServiceRender[GenerationService.renderReport()];
Normalizer[NormalizationService (discover/apply/validate)];
SubPipelineMerge[subPipeline._applyMerging()];
JsonUtilsExtract[jsonUtils.extractJsonString()];
JsonUtilsRepair[jsonUtils.repairBrokenJson()];
JsonUtilsSections[jsonUtils.extractSectionsFromDocument()];
JsonUtilsBuildCtx[jsonUtils.buildContinuationContext()];
BuildGenPrompt[subPromptBuilderGeneration.buildGenerationPrompt()];
UtilsSanitize[subSharedAiUtils.sanitizePromptContent()];
UtilsBuildPH[subSharedAiUtils.buildPromptWithPlaceholders()];
end
%% AiService
subgraph serviceAi mainServiceAi py - AiService
AiSvc_create[create()]
AiSvc_init[__init__()]
AiSvc_ensure[_ensureAiObjectsInitialized()]
AiSvc_initSubs[_initializeSubmodules()]
AiSvc_readImage[readImage()]
AiSvc_generateImage[generateImage()]
AiSvc_callPlan[callAiPlanning()]
AiSvc_callDocs[callAiDocuments()]
AiSvc_sanitize[sanitizePromptContent()]
end
AiSvc_create --> AiObjectsCall
AiSvc_create --> AiSvc_initSubs
AiSvc_initSubs --> ExtractionService
AiSvc_initSubs --> SubCore_new[SubCoreAi(...)]
AiSvc_initSubs --> SubDocProc_new[SubDocumentProcessing(...)]
AiSvc_initSubs --> SubDocGen_new[SubDocumentGeneration(...)]
AiSvc_ensure --> AiObjectsCall
AiSvc_ensure --> AiSvc_initSubs
AiSvc_readImage --> SubCore_readImage
AiSvc_generateImage --> SubCore_generateImage
AiSvc_callPlan --> SubCore_callPlan
AiSvc_callDocs --> SubCore_callDocs
AiSvc_sanitize --> UtilsSanitize
%% SubCoreAi
subgraph serviceAi subCoreAi py - SubCoreAi
SubCore_ctor[__init__()]
SubCore_analyze[_analyzePromptAndCreateOptions()]
SubCore_loop[_callAiWithLooping()]
SubCore_extract[_extractSectionsFromResponse()]
SubCore_should[_shouldContinueGeneration()]
SubCore_buildFinal[_buildFinalResultFromSections()]
SubCore_callPlan[callAiPlanning()]
SubCore_callDocs[callAiDocuments()]
SubCore_readImage[readImage()]
SubCore_generateImage[generateImage()]
end
SubCore_analyze --> AiObjectsCall
SubCore_analyze --> AiSvc_sanitize
SubCore_loop --> AiObjectsCall
SubCore_loop --> SubCore_extract
SubCore_loop --> SubCore_should
SubCore_loop --> SubCore_buildFinal
SubCore_extract --> JsonUtilsExtract
SubCore_extract --> JsonUtilsRepair
SubCore_extract --> JsonUtilsSections
SubCore_loop --> JsonUtilsBuildCtx
SubCore_callPlan --> UtilsBuildPH
SubCore_callPlan --> AiObjectsCall
SubCore_callDocs --> AiSvc_ensure
SubCore_callDocs --> SubCore_analyze
SubCore_callDocs --> BuildGenPrompt
SubCore_callDocs --> SubCore_loop
SubCore_callDocs --> GenServiceRender
SubCore_callDocs -->|documents present| AiSvc_callDocs_toDP[services.ai.documentProcessor.callAiText()]
SubCore_readImage --> AiObjectsCall
SubCore_generateImage --> AiObjectsGen
%% SubDocumentProcessing
subgraph serviceAi subDocumentProcessing py - SubDocumentProcessing
SDP_ctor[__init__()]
SDP_extractionService[prop: extractionService]
SDP_perChunk[processDocumentsPerChunk()]
SDP_perChunkJson[processDocumentsPerChunkJson()]
SDP_perChunkJsonPrompt[processDocumentsPerChunkJsonWithPrompt()]
SDP_withCont[processDocumentsWithContinuation()]
SDP_callText[callAiText()]
SDP_partsMap[_processPartsWithMapping()]
SDP_chunksMap[_processChunksWithMapping()]
SDP_mergeParts[_mergePartResults()]
SDP_convertPartsJson[_convertPartResultsToJson()]
SDP_mergeChunks[_mergeChunkResults()]
SDP_mergeChunksClean[_mergeChunkResultsClean()]
SDP_mergeChunksJson[_mergeChunkResultsJson()]
SDP_buildContPrompt[_buildContinuationPrompt()]
SDP_contLoop[_processWithContinuationLoop()]
SDP_buildIterPrompt[_buildContinuationIterationPrompt()]
end
SDP_extractionService --> ExtractionService
SDP_perChunk --> ExtractionService
SDP_perChunk --> SDP_partsMap
SDP_perChunk --> SDP_mergeParts
SDP_perChunkJson --> ExtractionService
SDP_perChunkJson --> SDP_partsMap
SDP_perChunkJson --> SDP_convertPartsJson
SDP_perChunkJson --> Normalizer
SDP_perChunkJsonPrompt --> ExtractionService
SDP_perChunkJsonPrompt --> SDP_chunksMap
SDP_perChunkJsonPrompt --> SDP_mergeChunksJson
SDP_withCont --> SDP_buildContPrompt
SDP_withCont --> SDP_contLoop
SDP_contLoop --> SDP_perChunkJsonPrompt
SDP_contLoop --> SDP_buildIterPrompt
SDP_callText --> SDP_perChunk
%% internals mapping to AI/external
SDP_partsMap --> AiObjectsCall
SDP_chunksMap --> SubCore_readImage
SDP_chunksMap --> AiObjectsCall
SDP_mergeParts --> SubPipelineMerge
SDP_convertPartsJson --> SubPipelineMerge
SDP_mergeChunks --> SubPipelineMerge
SDP_mergeChunksClean --> SubPipelineMerge
SDP_mergeChunksJson --> SubPipelineMerge
%% SubDocumentGeneration
subgraph serviceAi subDocumentGeneration py - SubDocumentGeneration
SDG_ctor[__init__()]
SDG_callGen[callAiWithDocumentGeneration()]
SDG_procUnified[_processDocumentsUnified()]
SDG_validateUnified[_validateUnifiedResponseStructure()]
SDG_validateDoc[_validateDocumentStructure()]
SDG_buildUnified[_buildUnifiedResult()]
SDG_processDoc[_processDocument()]
SDG_callAiJson[_callAiJson()]
SDG_postRaw[_postRawDataChatMessage()]
end
SDG_callGen --> GenServicePrompt
SDG_callGen --> SDG_procUnified
SDG_procUnified --> SDP_withCont
SDG_procUnified --> SDG_validateUnified
SDG_procUnified --> SDG_postRaw
SDG_buildUnified --> SDG_processDoc
SDG_processDoc --> BuildGenPrompt
SDG_processDoc --> AiObjectsCall
SDG_processDoc --> GenServiceRender
SDG_callAiJson --> SDP_perChunkJson
%% Cross-module interactions from AiService-created submodules (contextual)
AiSvc_initSubs --> SubCore_ctor
AiSvc_initSubs --> SDP_ctor
AiSvc_initSubs --> SDG_ctor
```

View file

@ -0,0 +1,115 @@
flowchart LR
%% Define colors for modules
classDef mainServiceAiStyle fill:#e3f2fd,stroke:#1976d2,stroke-width:3px
classDef serviceExtractionStyle fill:#fce4ec,stroke:#c2185b,stroke-width:3px
classDef serviceGenerationStyle fill:#e0f2f1,stroke:#00796b,stroke-width:3px
classDef serviceUtilsStyle fill:#fff9e0,stroke:#f57f17,stroke-width:3px
classDef interfacesStyle fill:#f3e5f5,stroke:#7b1fa2,stroke-width:3px
%% Declare all function nodes first
readImage[readImage]
generateImage[generateImage]
callAiPlanning[callAiPlanning]
callAiDocuments[callAiDocuments]
callAiText[callAiText]
_ensureAiObjectsInitialized[_ensureAiObjectsInitialized]
_initializeSubmodules[_initializeSubmodules]
_buildPromptWithPlaceholders[_buildPromptWithPlaceholders]
_analyzePromptAndCreateOptions[_analyzePromptAndCreateOptions]
_callAiWithLooping[_callAiWithLooping]
_extractSectionsFromResponse[_extractSectionsFromResponse]
_shouldContinueGeneration[_shouldContinueGeneration]
_buildFinalResultFromSections[_buildFinalResultFromSections]
ExtractionServiceExtract[ExtractionService.extractContent]
processDocumentsPerChunk[processDocumentsPerChunk]
_processPartsWithMapping[_processPartsWithMapping]
_mergePartResults[_mergePartResults]
SubPipelineMerge[subPipeline._applyMerging]
GenerationService[GenerationService.renderReport]
buildGenerationPrompt[buildGenerationPrompt]
sanitizePromptContent[sanitizePromptContent]
AiObjectsCall[AiObjects.call]
AiObjectsGenerateImage[AiObjects.generateImage]
%% Module subgraphs with functions
subgraph mainServiceAi[mainServiceAi]
readImage
generateImage
callAiPlanning
callAiDocuments
callAiText
_ensureAiObjectsInitialized
_initializeSubmodules
_buildPromptWithPlaceholders
_analyzePromptAndCreateOptions
_callAiWithLooping
_extractSectionsFromResponse
_shouldContinueGeneration
_buildFinalResultFromSections
end
subgraph serviceExtraction[serviceExtraction]
ExtractionServiceExtract
processDocumentsPerChunk
_processPartsWithMapping
_mergePartResults
SubPipelineMerge
end
subgraph serviceGeneration[serviceGeneration]
GenerationService
buildGenerationPrompt
end
subgraph serviceUtils[serviceUtils]
sanitizePromptContent
end
subgraph interfaces[interfaces]
AiObjectsCall
AiObjectsGenerateImage
end
%% Apply colors to subgraphs
class mainServiceAi mainServiceAiStyle
class serviceExtraction serviceExtractionStyle
class serviceGeneration serviceGenerationStyle
class serviceUtils serviceUtilsStyle
class interfaces interfacesStyle
%% mainServiceAi function calls
readImage --> _ensureAiObjectsInitialized
readImage --> AiObjectsCall
generateImage --> _ensureAiObjectsInitialized
generateImage --> AiObjectsGenerateImage
callAiPlanning --> _ensureAiObjectsInitialized
callAiPlanning --> _buildPromptWithPlaceholders
callAiPlanning --> AiObjectsCall
callAiDocuments --> _ensureAiObjectsInitialized
callAiDocuments --> _analyzePromptAndCreateOptions
callAiDocuments --> generateImage
callAiDocuments --> _callAiWithLooping
callAiDocuments --> callAiText
callAiDocuments --> buildGenerationPrompt
callAiDocuments --> GenerationService
callAiText --> _ensureAiObjectsInitialized
callAiText --> processDocumentsPerChunk
_ensureAiObjectsInitialized --> AiObjectsCall
_initializeSubmodules --> ExtractionServiceExtract
_analyzePromptAndCreateOptions --> AiObjectsCall
_analyzePromptAndCreateOptions --> sanitizePromptContent
_callAiWithLooping --> AiObjectsCall
_callAiWithLooping --> _extractSectionsFromResponse
_callAiWithLooping --> _shouldContinueGeneration
_callAiWithLooping --> _buildFinalResultFromSections
_buildPromptWithPlaceholders --> sanitizePromptContent
%% serviceExtraction function calls
processDocumentsPerChunk --> ExtractionServiceExtract
processDocumentsPerChunk --> _processPartsWithMapping
processDocumentsPerChunk --> _mergePartResults
_processPartsWithMapping --> AiObjectsCall
_mergePartResults --> SubPipelineMerge