file verbose trace with config var APP_DEBUG_CHAT_WORKFLOW_ENABLED installed
This commit is contained in:
parent
d9ee4d9605
commit
aa86caa229
5 changed files with 110 additions and 91 deletions
|
|
@ -571,7 +571,9 @@ class ChatObjects:
|
||||||
actionName=createdMessage.get("actionName")
|
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)
|
self._storeDebugMessageAndDocuments(chat_message)
|
||||||
|
|
||||||
return chat_message
|
return chat_message
|
||||||
|
|
|
||||||
|
|
@ -786,7 +786,9 @@ class AiService:
|
||||||
# Log extraction response
|
# Log extraction response
|
||||||
self.services.utils.debugLogToFile(f"EXTRACTION RESPONSE LENGTH: {len(ai_result) if ai_result else 0} characters", "AI_SERVICE")
|
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:
|
try:
|
||||||
import os
|
import os
|
||||||
from datetime import datetime, UTC
|
from datetime import datetime, UTC
|
||||||
|
|
@ -878,7 +880,9 @@ class AiService:
|
||||||
# Log extraction response length
|
# Log extraction response length
|
||||||
self.services.utils.debugLogToFile(f"EXTRACTION RESPONSE LENGTH: {len(ai_result) if ai_result else 0} characters", "AI_SERVICE")
|
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:
|
try:
|
||||||
import os
|
import os
|
||||||
from datetime import datetime, UTC
|
from datetime import datetime, UTC
|
||||||
|
|
@ -1325,7 +1329,6 @@ class AiService:
|
||||||
call_type = self._determineCallType(documents, options.operationType)
|
call_type = self._determineCallType(documents, options.operationType)
|
||||||
options.callType = call_type
|
options.callType = call_type
|
||||||
|
|
||||||
# Log the prompt being sent to AI for debugging (before routing) TODO TO REMOVE
|
|
||||||
try:
|
try:
|
||||||
# Build the full prompt that will be sent to AI
|
# Build the full prompt that will be sent to AI
|
||||||
if placeholders:
|
if placeholders:
|
||||||
|
|
@ -1349,7 +1352,7 @@ class AiService:
|
||||||
# Handle document generation with specific output format
|
# Handle document generation with specific output format
|
||||||
if outputFormat:
|
if outputFormat:
|
||||||
result = await self._callAiWithDocumentGeneration(prompt, documents, options, outputFormat, title)
|
result = await self._callAiWithDocumentGeneration(prompt, documents, options, outputFormat, title)
|
||||||
# Log AI response for debugging TODO TO REMOVE
|
# Log AI response for debugging
|
||||||
try:
|
try:
|
||||||
if isinstance(result, dict) and 'content' in result:
|
if isinstance(result, dict) and 'content' in result:
|
||||||
self._writeAiResponseDebug(
|
self._writeAiResponseDebug(
|
||||||
|
|
@ -1365,7 +1368,7 @@ class AiService:
|
||||||
|
|
||||||
if call_type == "planning":
|
if call_type == "planning":
|
||||||
result = await self._callAiPlanning(prompt, placeholders_dict, placeholders_meta, options)
|
result = await self._callAiPlanning(prompt, placeholders_dict, placeholders_meta, options)
|
||||||
# Log AI response for debugging TODO TO REMOVE
|
# Log AI response for debugging
|
||||||
try:
|
try:
|
||||||
self._writeAiResponseDebug(
|
self._writeAiResponseDebug(
|
||||||
label='ai_planning',
|
label='ai_planning',
|
||||||
|
|
@ -1390,7 +1393,7 @@ class AiService:
|
||||||
full_prompt = prompt
|
full_prompt = prompt
|
||||||
|
|
||||||
result = await self._callAiText(full_prompt, documents, options)
|
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:
|
try:
|
||||||
self._writeAiResponseDebug(
|
self._writeAiResponseDebug(
|
||||||
label='ai_text_main',
|
label='ai_text_main',
|
||||||
|
|
@ -1697,8 +1700,13 @@ class AiService:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def _writeAiResponseDebug(self, label: str, content: str, partIndex: int = 1, modelName: str = None, continuation: bool = None) -> None:
|
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:
|
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
|
import os
|
||||||
from datetime import datetime, UTC
|
from datetime import datetime, UTC
|
||||||
# Base dir: gateway/test-chat/ai (go up 4 levels from this file)
|
# Base dir: gateway/test-chat/ai (go up 4 levels from this file)
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ import logging
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from modules.datamodels.datamodelExtraction import ContentExtracted, ContentPart
|
from modules.datamodels.datamodelExtraction import ContentExtracted, ContentPart
|
||||||
|
from modules.shared.configuration import APP_CONFIG
|
||||||
from .subUtils import makeId
|
from .subUtils import makeId
|
||||||
from .subRegistry import ExtractorRegistry, ChunkerRegistry
|
from .subRegistry import ExtractorRegistry, ChunkerRegistry
|
||||||
from .merging.mergerText import TextMerger
|
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 after merging: {len(parts)} (chunks: {len(chunk_parts)})")
|
||||||
logger.debug(f"runExtraction - Final parts: {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:
|
try:
|
||||||
|
debug_enabled = APP_CONFIG.get("APP_DEBUG_CHAT_WORKFLOW_ENABLED", False)
|
||||||
|
if debug_enabled:
|
||||||
base_dir = "./test-chat/ai"
|
base_dir = "./test-chat/ai"
|
||||||
os.makedirs(base_dir, exist_ok=True)
|
os.makedirs(base_dir, exist_ok=True)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -318,8 +318,10 @@ class GenerationService:
|
||||||
if "sections" not in extractedContent:
|
if "sections" not in extractedContent:
|
||||||
raise ValueError("extractedContent must contain 'sections' field")
|
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:
|
try:
|
||||||
|
debug_enabled = self.services.utils.configGet("APP_DEBUG_CHAT_WORKFLOW_ENABLED", False)
|
||||||
|
if debug_enabled:
|
||||||
import os
|
import os
|
||||||
ts = datetime.now(UTC).strftime("%Y%m%d-%H%M%S")
|
ts = datetime.now(UTC).strftime("%Y%m%d-%H%M%S")
|
||||||
debug_root = "./test-chat/ai"
|
debug_root = "./test-chat/ai"
|
||||||
|
|
|
||||||
|
|
@ -114,8 +114,10 @@ Return only the JSON structure with actual data from the documents. Do not inclu
|
||||||
# Debug output
|
# Debug output
|
||||||
services.utils.debugLogToFile(f"EXTRACTION INTENT: Processed", "PROMPT_BUILDER")
|
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:
|
try:
|
||||||
|
debug_enabled = services.utils.configGet("APP_DEBUG_CHAT_WORKFLOW_ENABLED", False)
|
||||||
|
if debug_enabled:
|
||||||
import os
|
import os
|
||||||
from datetime import datetime, UTC
|
from datetime import datetime, UTC
|
||||||
ts = datetime.now(UTC).strftime("%Y%m%d-%H%M%S")
|
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
|
# Debug output
|
||||||
services.utils.debugLogToFile(f"GENERATION PROMPT: Generated successfully", "PROMPT_BUILDER")
|
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:
|
try:
|
||||||
|
debug_enabled = services.utils.configGet("APP_DEBUG_CHAT_WORKFLOW_ENABLED", False)
|
||||||
|
if debug_enabled:
|
||||||
import os
|
import os
|
||||||
from datetime import datetime, UTC
|
from datetime import datetime, UTC
|
||||||
ts = datetime.now(UTC).strftime("%Y%m%d-%H%M%S")
|
ts = datetime.now(UTC).strftime("%Y%m%d-%H%M%S")
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue