- Changes to support SpecialistID being passed iso CatalogID

- Removed error that stopped sync
This commit is contained in:
Josako
2024-11-15 13:13:33 +01:00
parent 1807435339
commit aa4ac3ec7c
2 changed files with 51 additions and 22 deletions

View File

@@ -133,12 +133,17 @@ def check_task_status(data):
elif task_result.state == 'SUCCESS': elif task_result.state == 'SUCCESS':
result = task_result.result result = task_result.result
current_app.logger.debug(f'SocketIO: Task {task_id} returned: {result}') current_app.logger.debug(f'SocketIO: Task {task_id} returned: {result}')
# Access the result structure correctly
specialist_result = result['result'] # This contains the SpecialistResult model_dump
response = { response = {
'status': 'success', 'status': 'success',
'taskId': task_id, 'taskId': task_id,
'answer': result['answer'], 'results': {
'citations': result['citations'], 'answer': specialist_result.get('answer'),
'algorithm': result['algorithm'], 'citations': specialist_result.get('citations', []),
'insufficient_info': specialist_result.get('insufficient_info', False)
},
'interaction_id': result['interaction_id'], 'interaction_id': result['interaction_id'],
} }
emit('task_status', response, room=room) emit('task_status', response, room=room)
@@ -146,7 +151,6 @@ def check_task_status(data):
current_app.logger.error(f'SocketIO: Task {task_id} has failed. Error: {task_result.info}') current_app.logger.error(f'SocketIO: Task {task_id} has failed. Error: {task_result.info}')
emit('task_status', {'status': task_result.state, 'message': str(task_result.info)}, room=room) emit('task_status', {'status': task_result.state, 'message': str(task_result.info)}, room=room)
@socketio.on('feedback') @socketio.on('feedback')
def handle_feedback(data): def handle_feedback(data):
try: try:

View File

@@ -82,7 +82,7 @@ class EveAIChatWidget extends HTMLElement {
} }
updateAttributes() { updateAttributes() {
this.tenantId = this.getAttribute('tenant-id'); this.tenantId = parseInt(this.getAttribute('tenant-id'));
this.apiKey = this.getAttribute('api-key'); this.apiKey = this.getAttribute('api-key');
this.domain = this.getAttribute('domain'); this.domain = this.getAttribute('domain');
this.language = this.getAttribute('language'); this.language = this.getAttribute('language');
@@ -163,7 +163,8 @@ class EveAIChatWidget extends HTMLElement {
}, },
reconnectionAttempts: Infinity, // Infinite reconnection attempts reconnectionAttempts: Infinity, // Infinite reconnection attempts
reconnectionDelay: 5000, // Delay between reconnections reconnectionDelay: 5000, // Delay between reconnections
timeout: 20000 // Connection timeout timeout: 20000, // Connection timeout
debug: true
}); });
console.log(`Finished initializing socket connection to Evie`); console.log(`Finished initializing socket connection to Evie`);
@@ -235,28 +236,19 @@ class EveAIChatWidget extends HTMLElement {
}); });
this.socket.on('bot_response', (data) => { this.socket.on('bot_response', (data) => {
console.log('Bot response received: ', data);
console.log('data tenantId: ', data.tenantId)
console.log('this tenantId: ', this.tenantId)
if (data.tenantId === this.tenantId) { if (data.tenantId === this.tenantId) {
console.log('Initial response received:', data); console.log('Starting task status check for:', data.taskId);
console.log('Task ID received:', data.taskId); setTimeout(() => this.startTaskCheck(data.taskId), 1000);
this.checkTaskStatus(data.taskId);
this.setStatusMessage('Processing...'); this.setStatusMessage('Processing...');
} }
}); });
this.socket.on('task_status', (data) => { this.socket.on('task_status', (data) => {
console.log('Task status received:', data.status); console.log('Task status received:', data);
console.log('Task ID received:', data.taskId); this.handleTaskStatus(data);
console.log('Citations type:', typeof data.results.citations, 'Citations:', data.results.citations);
if (data.status === 'pending') {
this.updateProgress();
setTimeout(() => this.checkTaskStatus(data.taskId), 1000); // Poll every second
} else if (data.status === 'success') {
this.addBotMessage(data.results.answer, data.interaction_id, data.algorithm, data.results.citations || []);
this.clearProgress(); // Clear progress indicator when done
} else {
this.setStatusMessage('Failed to process message.');
}
}); });
} }
@@ -442,6 +434,39 @@ toggleFeedback(thumbsUp, thumbsDown, feedback, interactionId) {
} }
} }
startTaskCheck(taskId) {
console.log('Emitting check_task_status for:', taskId);
this.socket.emit('check_task_status', {
task_id: taskId,
token: this.jwtToken,
tenantId: this.tenantId
});
}
handleTaskStatus(data) {
console.log('Handling task status:', data);
if (data.status === 'pending') {
this.updateProgress();
// Continue checking
setTimeout(() => this.startTaskCheck(data.taskId), 1000);
} else if (data.status === 'success') {
if (data.results) {
this.addBotMessage(
data.results.answer,
data.interaction_id,
'RAG_TENANT',
data.results.citations || []
);
} else {
console.error('Missing results in task status response:', data);
}
this.clearProgress();
} else {
console.error('Task error:', data);
this.setStatusMessage('Failed to process message.');
}
}
sendMessageToBackend(message) { sendMessageToBackend(message) {
console.log('sendMessageToBackend called'); console.log('sendMessageToBackend called');
if (!this.socket) { if (!this.socket) {