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 os
|
||||||
import logging
|
import logging
|
||||||
import uuid
|
import uuid
|
||||||
|
import time
|
||||||
from datetime import datetime, UTC
|
from datetime import datetime, UTC
|
||||||
from typing import Dict, Any, List, Optional, Union
|
from typing import Dict, Any, List, Optional, Union
|
||||||
|
|
||||||
|
|
@ -167,7 +168,12 @@ class ChatObjects:
|
||||||
startedAt=workflow.get("startedAt", self._getCurrentTimestamp()),
|
startedAt=workflow.get("startedAt", self._getCurrentTimestamp()),
|
||||||
logs=[ChatLog(**log) for log in workflow.get("logs", [])],
|
logs=[ChatLog(**log) for log in workflow.get("logs", [])],
|
||||||
messages=[ChatMessage(**msg) for msg in workflow.get("messages", [])],
|
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)
|
mandateId=workflow.get("mandateId", self.currentUser.mandateId)
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
@ -230,7 +236,12 @@ class ChatObjects:
|
||||||
startedAt=updated.get("startedAt", workflow.startedAt),
|
startedAt=updated.get("startedAt", workflow.startedAt),
|
||||||
logs=[ChatLog(**log) for log in updated.get("logs", workflow.logs)],
|
logs=[ChatLog(**log) for log in updated.get("logs", workflow.logs)],
|
||||||
messages=[ChatMessage(**msg) for msg in updated.get("messages", workflow.messages)],
|
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)
|
mandateId=updated.get("mandateId", workflow.mandateId)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -328,10 +339,6 @@ class ChatObjects:
|
||||||
stats=ChatStat(**createdMessage.get("stats", {})) if createdMessage.get("stats") else None
|
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:
|
except Exception as e:
|
||||||
logger.error(f"Error creating workflow message: {str(e)}")
|
logger.error(f"Error creating workflow message: {str(e)}")
|
||||||
return None
|
return None
|
||||||
|
|
@ -553,22 +560,31 @@ class ChatObjects:
|
||||||
logger.error(f"No permission to update workflow {workflowId} stats")
|
logger.error(f"No permission to update workflow {workflowId} stats")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# Get current stats
|
# Get current stats - ensure we have proper defaults
|
||||||
currentStats = workflow.stats.dict() if workflow.stats else {
|
if workflow.stats:
|
||||||
"bytesSent": 0,
|
currentStats = workflow.stats.dict()
|
||||||
"bytesReceived": 0,
|
# Ensure all required fields exist
|
||||||
"tokenCount": 0,
|
currentStats.setdefault("bytesSent", 0)
|
||||||
"processingTime": 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
|
# Simple processing time - just use current time
|
||||||
workflow_start = datetime.fromisoformat(workflow.startedAt.replace('Z', '+00:00'))
|
processing_time = time.time()
|
||||||
current_time = datetime.now(UTC)
|
|
||||||
processing_time = (current_time - workflow_start).total_seconds()
|
|
||||||
|
|
||||||
# Update stats with incremental values
|
# Update stats with incremental values - ensure no None values
|
||||||
currentStats["bytesSent"] = currentStats.get("bytesSent", 0) + bytesSent
|
current_bytes_sent = currentStats.get("bytesSent", 0) or 0
|
||||||
currentStats["bytesReceived"] = currentStats.get("bytesReceived", 0) + bytesReceived
|
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["tokenCount"] = currentStats["bytesSent"] + currentStats["bytesReceived"]
|
||||||
currentStats["processingTime"] = processing_time
|
currentStats["processingTime"] = processing_time
|
||||||
|
|
||||||
|
|
@ -840,6 +856,9 @@ class ChatObjects:
|
||||||
# Create workflow
|
# Create workflow
|
||||||
workflow = self.createWorkflow(workflowData)
|
workflow = self.createWorkflow(workflowData)
|
||||||
|
|
||||||
|
# Initialize stats for the new workflow
|
||||||
|
self.updateWorkflowStats(workflow.id, bytesSent=0, bytesReceived=0)
|
||||||
|
|
||||||
# Remove the 'Workflow started' log entry
|
# Remove the 'Workflow started' log entry
|
||||||
|
|
||||||
# Start workflow processing
|
# Start workflow processing
|
||||||
|
|
|
||||||
|
|
@ -71,7 +71,12 @@ async def get_workflows(
|
||||||
startedAt=workflow_data.get("startedAt", appInterface._getCurrentTimestamp()),
|
startedAt=workflow_data.get("startedAt", appInterface._getCurrentTimestamp()),
|
||||||
logs=[ChatLog(**log) for log in workflow_data.get("logs", [])],
|
logs=[ChatLog(**log) for log in workflow_data.get("logs", [])],
|
||||||
messages=[ChatMessage(**msg) for msg in workflow_data.get("messages", [])],
|
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 "")
|
mandateId=workflow_data.get("mandateId", currentUser.mandateId or "")
|
||||||
)
|
)
|
||||||
workflows.append(workflow)
|
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)
|
message = await self._sendFirstMessage(userInput, workflow)
|
||||||
|
|
||||||
# Execute unified workflow
|
# Execute unified workflow
|
||||||
workflow_result = await self.chatManager.executeUnifiedWorkflow(userInput.prompt, workflow)
|
workflow_result = await self.chatManager.executeUnifiedWorkflow(userInput, workflow)
|
||||||
|
|
||||||
# Process workflow results
|
# Process workflow results
|
||||||
await self._processWorkflowResults(workflow, workflow_result, message)
|
await self._processWorkflowResults(workflow, workflow_result, message)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue