system scope 3
This commit is contained in:
parent
d1aac4099d
commit
5687b1aec7
4 changed files with 911 additions and 544 deletions
|
|
@ -6,6 +6,7 @@ Uses the JSON connector for data access with added language support.
|
|||
import os
|
||||
import logging
|
||||
import uuid
|
||||
import time
|
||||
from datetime import datetime, UTC
|
||||
from typing import Dict, Any, List, Optional, Union
|
||||
|
||||
|
|
@ -167,7 +168,12 @@ class ChatObjects:
|
|||
startedAt=workflow.get("startedAt", self._getCurrentTimestamp()),
|
||||
logs=[ChatLog(**log) for log in workflow.get("logs", [])],
|
||||
messages=[ChatMessage(**msg) for msg in workflow.get("messages", [])],
|
||||
stats=ChatStat(**workflow.get("dataStats", {})) if workflow.get("dataStats") else None,
|
||||
stats=ChatStat(**workflow.get("dataStats", {})) if workflow.get("dataStats") else ChatStat(
|
||||
bytesSent=0,
|
||||
bytesReceived=0,
|
||||
tokenCount=0,
|
||||
processingTime=0
|
||||
),
|
||||
mandateId=workflow.get("mandateId", self.currentUser.mandateId)
|
||||
)
|
||||
except Exception as e:
|
||||
|
|
@ -230,7 +236,12 @@ class ChatObjects:
|
|||
startedAt=updated.get("startedAt", workflow.startedAt),
|
||||
logs=[ChatLog(**log) for log in updated.get("logs", workflow.logs)],
|
||||
messages=[ChatMessage(**msg) for msg in updated.get("messages", workflow.messages)],
|
||||
stats=ChatStat(**updated.get("dataStats", workflow.stats.dict() if workflow.stats else {})) if updated.get("dataStats") or workflow.stats else None,
|
||||
stats=ChatStat(**updated.get("dataStats", workflow.stats.dict() if workflow.stats else {})) if updated.get("dataStats") or workflow.stats else ChatStat(
|
||||
bytesSent=0,
|
||||
bytesReceived=0,
|
||||
tokenCount=0,
|
||||
processingTime=0
|
||||
),
|
||||
mandateId=updated.get("mandateId", workflow.mandateId)
|
||||
)
|
||||
|
||||
|
|
@ -327,11 +338,7 @@ class ChatObjects:
|
|||
publishedAt=createdMessage.get("publishedAt", self._getCurrentTimestamp()),
|
||||
stats=ChatStat(**createdMessage.get("stats", {})) if createdMessage.get("stats") else None
|
||||
)
|
||||
|
||||
# Update workflow stats for message creation (estimate bytes for message)
|
||||
message_size = len(createdMessage.get("message", "")) + sum(len(doc.get("filename", "")) for doc in createdMessage.get("documents", []))
|
||||
self.updateWorkflowStats(workflowId, bytesSent=0, bytesReceived=message_size)
|
||||
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error creating workflow message: {str(e)}")
|
||||
return None
|
||||
|
|
@ -553,22 +560,31 @@ class ChatObjects:
|
|||
logger.error(f"No permission to update workflow {workflowId} stats")
|
||||
return False
|
||||
|
||||
# Get current stats
|
||||
currentStats = workflow.stats.dict() if workflow.stats else {
|
||||
"bytesSent": 0,
|
||||
"bytesReceived": 0,
|
||||
"tokenCount": 0,
|
||||
"processingTime": 0
|
||||
}
|
||||
# Get current stats - ensure we have proper defaults
|
||||
if workflow.stats:
|
||||
currentStats = workflow.stats.dict()
|
||||
# Ensure all required fields exist
|
||||
currentStats.setdefault("bytesSent", 0)
|
||||
currentStats.setdefault("bytesReceived", 0)
|
||||
currentStats.setdefault("tokenCount", 0)
|
||||
currentStats.setdefault("processingTime", 0)
|
||||
else:
|
||||
currentStats = {
|
||||
"bytesSent": 0,
|
||||
"bytesReceived": 0,
|
||||
"tokenCount": 0,
|
||||
"processingTime": 0
|
||||
}
|
||||
|
||||
# Calculate processing time from workflow start
|
||||
workflow_start = datetime.fromisoformat(workflow.startedAt.replace('Z', '+00:00'))
|
||||
current_time = datetime.now(UTC)
|
||||
processing_time = (current_time - workflow_start).total_seconds()
|
||||
# Simple processing time - just use current time
|
||||
processing_time = time.time()
|
||||
|
||||
# Update stats with incremental values
|
||||
currentStats["bytesSent"] = currentStats.get("bytesSent", 0) + bytesSent
|
||||
currentStats["bytesReceived"] = currentStats.get("bytesReceived", 0) + bytesReceived
|
||||
# Update stats with incremental values - ensure no None values
|
||||
current_bytes_sent = currentStats.get("bytesSent", 0) or 0
|
||||
current_bytes_received = currentStats.get("bytesReceived", 0) or 0
|
||||
|
||||
currentStats["bytesSent"] = current_bytes_sent + bytesSent
|
||||
currentStats["bytesReceived"] = current_bytes_received + bytesReceived
|
||||
currentStats["tokenCount"] = currentStats["bytesSent"] + currentStats["bytesReceived"]
|
||||
currentStats["processingTime"] = processing_time
|
||||
|
||||
|
|
@ -840,6 +856,9 @@ class ChatObjects:
|
|||
# Create workflow
|
||||
workflow = self.createWorkflow(workflowData)
|
||||
|
||||
# Initialize stats for the new workflow
|
||||
self.updateWorkflowStats(workflow.id, bytesSent=0, bytesReceived=0)
|
||||
|
||||
# Remove the 'Workflow started' log entry
|
||||
|
||||
# Start workflow processing
|
||||
|
|
|
|||
|
|
@ -71,7 +71,12 @@ async def get_workflows(
|
|||
startedAt=workflow_data.get("startedAt", appInterface._getCurrentTimestamp()),
|
||||
logs=[ChatLog(**log) for log in workflow_data.get("logs", [])],
|
||||
messages=[ChatMessage(**msg) for msg in workflow_data.get("messages", [])],
|
||||
stats=ChatStat(**workflow_data.get("dataStats", {})) if workflow_data.get("dataStats") else None,
|
||||
stats=ChatStat(**workflow_data.get("dataStats", {})) if workflow_data.get("dataStats") else ChatStat(
|
||||
bytesSent=0,
|
||||
bytesReceived=0,
|
||||
tokenCount=0,
|
||||
processingTime=0
|
||||
),
|
||||
mandateId=workflow_data.get("mandateId", currentUser.mandateId or "")
|
||||
)
|
||||
workflows.append(workflow)
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -42,7 +42,7 @@ class WorkflowManager:
|
|||
message = await self._sendFirstMessage(userInput, workflow)
|
||||
|
||||
# Execute unified workflow
|
||||
workflow_result = await self.chatManager.executeUnifiedWorkflow(userInput.prompt, workflow)
|
||||
workflow_result = await self.chatManager.executeUnifiedWorkflow(userInput, workflow)
|
||||
|
||||
# Process workflow results
|
||||
await self._processWorkflowResults(workflow, workflow_result, message)
|
||||
|
|
|
|||
Loading…
Reference in a new issue