fixed kpi identification
This commit is contained in:
parent
bd893ef072
commit
a8ef757046
1 changed files with 18 additions and 23 deletions
|
|
@ -316,9 +316,10 @@ Respond with ONLY a JSON object in this exact format:
|
||||||
if accumulationState and accumulationState.isAccumulationMode and iteration == 1 and not accumulationState.kpis:
|
if accumulationState and accumulationState.isAccumulationMode and iteration == 1 and not accumulationState.kpis:
|
||||||
logger.info(f"Iteration {iteration}: Defining KPIs for accumulation tracking")
|
logger.info(f"Iteration {iteration}: Defining KPIs for accumulation tracking")
|
||||||
continuationContext = buildContinuationContext(allSections, result)
|
continuationContext = buildContinuationContext(allSections, result)
|
||||||
|
# Pass raw response string from first iteration for KPI definition
|
||||||
kpiDefinitions = await self._defineKpisFromPrompt(
|
kpiDefinitions = await self._defineKpisFromPrompt(
|
||||||
userPrompt or prompt,
|
userPrompt or prompt,
|
||||||
parsedResult,
|
result, # Pass raw JSON string from first iteration
|
||||||
continuationContext,
|
continuationContext,
|
||||||
debugPrefix
|
debugPrefix
|
||||||
)
|
)
|
||||||
|
|
@ -509,46 +510,40 @@ Respond with ONLY a JSON object in this exact format:
|
||||||
async def _defineKpisFromPrompt(
|
async def _defineKpisFromPrompt(
|
||||||
self,
|
self,
|
||||||
userPrompt: str,
|
userPrompt: str,
|
||||||
parsedJson: Optional[Dict[str, Any]],
|
rawJsonString: Optional[str],
|
||||||
continuationContext: Dict[str, Any],
|
continuationContext: Dict[str, Any],
|
||||||
debugPrefix: str = "kpi"
|
debugPrefix: str = "kpi"
|
||||||
) -> List[Dict[str, Any]]:
|
) -> List[Dict[str, Any]]:
|
||||||
"""
|
"""
|
||||||
Make separate AI call to define KPIs based on user prompt and delivered data.
|
Make separate AI call to define KPIs based on user prompt and incomplete JSON.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
userPrompt: Original user prompt
|
userPrompt: Original user prompt
|
||||||
parsedJson: Parsed JSON from first iteration (if available)
|
rawJsonString: Raw JSON string from first iteration response
|
||||||
continuationContext: Continuation context with delivered summary
|
continuationContext: Continuation context (not used for JSON, kept for compatibility)
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
List of KPI definitions: [{"id": str, "description": str, "jsonPath": str, "targetValue": int}, ...]
|
List of KPI definitions: [{"id": str, "description": str, "jsonPath": str, "targetValue": int}, ...]
|
||||||
"""
|
"""
|
||||||
deliveredSummary = continuationContext.get("delivered_summary", "")
|
# Use raw JSON string from first iteration response
|
||||||
cutOffElement = continuationContext.get("cut_off_element")
|
if rawJsonString:
|
||||||
elementBeforeCutoff = continuationContext.get("element_before_cutoff")
|
# Remove markdown code fences if present
|
||||||
|
from modules.shared.jsonUtils import stripCodeFences
|
||||||
|
incompleteJson = stripCodeFences(rawJsonString.strip())
|
||||||
|
else:
|
||||||
|
incompleteJson = "Not available"
|
||||||
|
|
||||||
# Build prompt for KPI definition
|
kpiDefinitionPrompt = f"""Analyze the user request and incomplete JSON to define KPIs (Key Performance Indicators) for tracking progress.
|
||||||
kpiDefinitionPrompt = f"""Analyze the user request and delivered data to define KPIs (Key Performance Indicators) for tracking progress.
|
|
||||||
|
|
||||||
User Request:
|
User Request:
|
||||||
{userPrompt}
|
{userPrompt}
|
||||||
|
|
||||||
Delivered Data Summary:
|
Delivered JSON part:
|
||||||
{deliveredSummary}
|
{incompleteJson}
|
||||||
|
|
||||||
Current JSON Structure (if available):
|
|
||||||
{json.dumps(parsedJson, indent=2) if parsedJson else "Not available"}
|
|
||||||
|
|
||||||
Cut-off Element:
|
|
||||||
{cutOffElement if cutOffElement else "Not available"}
|
|
||||||
|
|
||||||
Last Complete Element:
|
|
||||||
{elementBeforeCutoff if elementBeforeCutoff else "Not available"}
|
|
||||||
|
|
||||||
Task: Define which JSON items should be tracked to measure completion progress.
|
Task: Define which JSON items should be tracked to measure completion progress.
|
||||||
|
|
||||||
IMPORTANT: Analyze the JSON structure to understand what is being tracked:
|
IMPORTANT: Analyze the Delivered JSON part structure to understand what is being tracked:
|
||||||
1. Identify the structure type (table with rows, list with items, etc.)
|
1. Identify the structure type (table with rows, list with items, etc.)
|
||||||
2. Determine what the jsonPath actually counts (number of rows, number of items, etc.)
|
2. Determine what the jsonPath actually counts (number of rows, number of items, etc.)
|
||||||
3. Calculate targetValue based on what is being tracked, NOT the total quantity requested
|
3. Calculate targetValue based on what is being tracked, NOT the total quantity requested
|
||||||
|
|
@ -556,7 +551,7 @@ IMPORTANT: Analyze the JSON structure to understand what is being tracked:
|
||||||
For each trackable item, provide:
|
For each trackable item, provide:
|
||||||
- id: Unique identifier (use descriptive name)
|
- id: Unique identifier (use descriptive name)
|
||||||
- description: What this KPI measures (be specific about what is counted)
|
- description: What this KPI measures (be specific about what is counted)
|
||||||
- jsonPath: Path to extract value from JSON (use dot notation with array indices, e.g., "documents[0].sections[0].elements")
|
- jsonPath: Path to extract value from JSON (use dot notation with array indices, e.g., "documents[0].sections[1].elements[0].rows")
|
||||||
- targetValue: Target value to reach (integer) - MUST match what jsonPath actually tracks (rows count, items count, etc.)
|
- targetValue: Target value to reach (integer) - MUST match what jsonPath actually tracks (rows count, items count, etc.)
|
||||||
|
|
||||||
Return ONLY valid JSON in this format:
|
Return ONLY valid JSON in this format:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue