file verbose trace with config var APP_DEBUG_CHAT_WORKFLOW_ENABLED installed

This commit is contained in:
ValueOn AG 2025-10-12 14:59:51 +02:00
parent d9ee4d9605
commit aa86caa229
5 changed files with 110 additions and 91 deletions

View file

@ -571,7 +571,9 @@ class ChatObjects:
actionName=createdMessage.get("actionName")
)
# Debug: Store message and documents for debugging TODO REMOVE
# Debug: Store message and documents for debugging - only if debug enabled
debug_enabled = APP_CONFIG.get("APP_DEBUG_CHAT_WORKFLOW_ENABLED", False)
if debug_enabled:
self._storeDebugMessageAndDocuments(chat_message)
return chat_message

View file

@ -786,7 +786,9 @@ class AiService:
# Log extraction response
self.services.utils.debugLogToFile(f"EXTRACTION RESPONSE LENGTH: {len(ai_result) if ai_result else 0} characters", "AI_SERVICE")
# Save full extraction prompt and response to debug file
# Save full extraction prompt and response to debug file - only if debug enabled
debug_enabled = self.services.utils.configGet("APP_DEBUG_CHAT_WORKFLOW_ENABLED", False)
if debug_enabled:
try:
import os
from datetime import datetime, UTC
@ -878,7 +880,9 @@ class AiService:
# Log extraction response length
self.services.utils.debugLogToFile(f"EXTRACTION RESPONSE LENGTH: {len(ai_result) if ai_result else 0} characters", "AI_SERVICE")
# Save extraction response to debug file (without verbose prompt)
# Save extraction response to debug file (without verbose prompt) - only if debug enabled
debug_enabled = self.services.utils.configGet("APP_DEBUG_CHAT_WORKFLOW_ENABLED", False)
if debug_enabled:
try:
import os
from datetime import datetime, UTC
@ -1325,7 +1329,6 @@ class AiService:
call_type = self._determineCallType(documents, options.operationType)
options.callType = call_type
# Log the prompt being sent to AI for debugging (before routing) TODO TO REMOVE
try:
# Build the full prompt that will be sent to AI
if placeholders:
@ -1349,7 +1352,7 @@ class AiService:
# Handle document generation with specific output format
if outputFormat:
result = await self._callAiWithDocumentGeneration(prompt, documents, options, outputFormat, title)
# Log AI response for debugging TODO TO REMOVE
# Log AI response for debugging
try:
if isinstance(result, dict) and 'content' in result:
self._writeAiResponseDebug(
@ -1365,7 +1368,7 @@ class AiService:
if call_type == "planning":
result = await self._callAiPlanning(prompt, placeholders_dict, placeholders_meta, options)
# Log AI response for debugging TODO TO REMOVE
# Log AI response for debugging
try:
self._writeAiResponseDebug(
label='ai_planning',
@ -1390,7 +1393,7 @@ class AiService:
full_prompt = prompt
result = await self._callAiText(full_prompt, documents, options)
# Log AI response for debugging (additional logging for text calls) TODO TO REMOVE
# Log AI response for debugging (additional logging for text calls)
try:
self._writeAiResponseDebug(
label='ai_text_main',
@ -1697,8 +1700,13 @@ class AiService:
pass
def _writeAiResponseDebug(self, label: str, content: str, partIndex: int = 1, modelName: str = None, continuation: bool = None) -> None:
"""Persist raw AI response parts for debugging under test-chat/ai."""
"""Persist raw AI response parts for debugging under test-chat/ai - only if debug enabled."""
try:
# Check if debug logging is enabled
debug_enabled = self.services.utils.configGet("APP_DEBUG_CHAT_WORKFLOW_ENABLED", False)
if not debug_enabled:
return
import os
from datetime import datetime, UTC
# Base dir: gateway/test-chat/ai (go up 4 levels from this file)

View file

@ -3,6 +3,7 @@ import logging
import os
from modules.datamodels.datamodelExtraction import ContentExtracted, ContentPart
from modules.shared.configuration import APP_CONFIG
from .subUtils import makeId
from .subRegistry import ExtractorRegistry, ChunkerRegistry
from .merging.mergerText import TextMerger
@ -100,8 +101,10 @@ def runExtraction(extractorRegistry: ExtractorRegistry, chunkerRegistry: Chunker
logger.debug(f"runExtraction: Final parts after merging: {len(parts)} (chunks: {len(chunk_parts)})")
logger.debug(f"runExtraction - Final parts: {len(parts)} (chunks: {len(chunk_parts)})")
# DEBUG: dump parts and chunks to files TODO TO REMOVE
# DEBUG: dump parts and chunks to files - only if debug enabled
try:
debug_enabled = APP_CONFIG.get("APP_DEBUG_CHAT_WORKFLOW_ENABLED", False)
if debug_enabled:
base_dir = "./test-chat/ai"
os.makedirs(base_dir, exist_ok=True)

View file

@ -318,8 +318,10 @@ class GenerationService:
if "sections" not in extractedContent:
raise ValueError("extractedContent must contain 'sections' field")
# DEBUG: Log renderer input metadata only (no verbose JSON) TODO REMOVE
# DEBUG: Log renderer input metadata only (no verbose JSON) - only if debug enabled
try:
debug_enabled = self.services.utils.configGet("APP_DEBUG_CHAT_WORKFLOW_ENABLED", False)
if debug_enabled:
import os
ts = datetime.now(UTC).strftime("%Y%m%d-%H%M%S")
debug_root = "./test-chat/ai"

View file

@ -114,8 +114,10 @@ Return only the JSON structure with actual data from the documents. Do not inclu
# Debug output
services.utils.debugLogToFile(f"EXTRACTION INTENT: Processed", "PROMPT_BUILDER")
# Save full extraction prompt to debug file
# Save full extraction prompt to debug file - only if debug enabled
try:
debug_enabled = services.utils.configGet("APP_DEBUG_CHAT_WORKFLOW_ENABLED", False)
if debug_enabled:
import os
from datetime import datetime, UTC
ts = datetime.now(UTC).strftime("%Y%m%d-%H%M%S")
@ -194,8 +196,10 @@ Return only the generation prompt, starting with "Generate a {outputFormat} docu
# Debug output
services.utils.debugLogToFile(f"GENERATION PROMPT: Generated successfully", "PROMPT_BUILDER")
# Save full generation prompt and AI response to debug file
# Save full generation prompt and AI response to debug file - only if debug enabled
try:
debug_enabled = services.utils.configGet("APP_DEBUG_CHAT_WORKFLOW_ENABLED", False)
if debug_enabled:
import os
from datetime import datetime, UTC
ts = datetime.now(UTC).strftime("%Y%m%d-%H%M%S")