Spaces:
Sleeping
Sleeping
Commit ·
feec993
1
Parent(s): 8e31f57
Refactor code to update message content and labels in FlaskApp and dashboard templates
Browse files- app/app.py +2 -2
- app/templates/admin_dashboard.html +42 -53
- app/templates/dashboard.html +7 -18
app/app.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
from flask import Flask, render_template, request, redirect, url_for, flash, session, jsonify
|
| 2 |
-
|
| 3 |
-
from agent import GroqAgent
|
| 4 |
|
| 5 |
class FlaskApp:
|
| 6 |
def __init__(self, agents):
|
|
|
|
| 1 |
from flask import Flask, render_template, request, redirect, url_for, flash, session, jsonify
|
| 2 |
+
from .agent import GroqAgent
|
| 3 |
+
# from agent import GroqAgent
|
| 4 |
|
| 5 |
class FlaskApp:
|
| 6 |
def __init__(self, agents):
|
app/templates/admin_dashboard.html
CHANGED
|
@@ -8,47 +8,39 @@
|
|
| 8 |
|
| 9 |
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
| 10 |
<script>
|
|
|
|
|
|
|
|
|
|
| 11 |
function fetchPendingMessages() {
|
| 12 |
-
// Fetch pending messages from the server
|
| 13 |
$.getJSON('/get_pending_messages', function(data) {
|
| 14 |
-
|
| 15 |
-
|
| 16 |
if (data.length === 0) {
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
}
|
| 21 |
-
|
| 22 |
-
let pendingMessageList = ''; // Clear out old list
|
| 23 |
-
data.forEach(function(message, index) {
|
| 24 |
-
// Dynamically build the list of pending messages
|
| 25 |
-
pendingMessageList += `
|
| 26 |
-
<li class="pending-message">
|
| 27 |
-
<p>${message.content} (Author: ${message.author})</p>
|
| 28 |
-
<div class="button-container">
|
| 29 |
-
<form action="/admin_dashboard" method="POST" style="display: inline;">
|
| 30 |
-
<input type="hidden" name="message_id" value="${index}">
|
| 31 |
-
<button type="submit" name="action" value="approve" class="button approve">Approve</button>
|
| 32 |
-
</form>
|
| 33 |
-
<form action="/admin_dashboard" method="POST" style="display: inline;">
|
| 34 |
-
<input type="hidden" name="message_id" value="${index}">
|
| 35 |
-
<button type="submit" name="action" value="delete" class="button delete">Delete</button>
|
| 36 |
-
</form>
|
| 37 |
-
</div>
|
| 38 |
-
</li>`;
|
| 39 |
-
});
|
| 40 |
-
|
| 41 |
-
// Insert the generated list into the DOM
|
| 42 |
$('#pending-message-list').html(pendingMessageList);
|
| 43 |
-
})
|
| 44 |
-
.fail(function() {
|
| 45 |
-
console.error("Error fetching pending messages from server.");
|
| 46 |
-
$('#pending-message-list').html("<li>Error fetching pending messages.</li>");
|
| 47 |
});
|
| 48 |
}
|
| 49 |
-
|
| 50 |
-
// Function to fetch message history and
|
| 51 |
-
function
|
|
|
|
| 52 |
$.getJSON('/get_message_history', function(data) {
|
| 53 |
let messageHistory = '';
|
| 54 |
data.forEach(function(message) {
|
|
@@ -70,9 +62,11 @@
|
|
| 70 |
|
| 71 |
$('#message-history').html(messageHistory);
|
| 72 |
});
|
|
|
|
|
|
|
|
|
|
| 73 |
}
|
| 74 |
|
| 75 |
-
// Function to fetch agent order immediately
|
| 76 |
// Function to fetch agent order immediately
|
| 77 |
function fetchAgentOrder() {
|
| 78 |
$.getJSON('/get_agent_order', function(agentData) {
|
|
@@ -81,15 +75,22 @@
|
|
| 81 |
});
|
| 82 |
}
|
| 83 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
// Poll the server every 1 second to update the message history and pending messages
|
| 85 |
// Fetch the agent order and then the message history every 2 seconds
|
| 86 |
setInterval(function() {
|
| 87 |
fetchAgentOrder(); // Fetch the dynamic agent order
|
| 88 |
-
|
| 89 |
-
fetchPendingMessages(); // Fetch and display the pending messages for approval
|
| 90 |
}, 1000);
|
| 91 |
</script>
|
| 92 |
</head>
|
|
|
|
| 93 |
<body>
|
| 94 |
<div class="container admin-dashboard-container">
|
| 95 |
<h2>Send a Message to the User</h2>
|
|
@@ -103,25 +104,13 @@
|
|
| 103 |
|
| 104 |
<h2>Message History</h2>
|
| 105 |
<ul class="message-history" id="message-history">
|
| 106 |
-
|
| 107 |
-
<li><strong>
|
| 108 |
-
{% if message.author == 'Admin' %}
|
| 109 |
-
{{ message.author }} - Agent {{ agent_order[0] }}:
|
| 110 |
-
{% elif message.author == 'llm2' %}
|
| 111 |
-
{{ message.author }} - Agent {{ agent_order[1] }}:
|
| 112 |
-
{% elif message.author == 'llm3' %}
|
| 113 |
-
{{ message.author }} - Agent{{ agent_order[2] }}:
|
| 114 |
-
{% elif message.author == 'User' %}
|
| 115 |
-
{{ message.author }}
|
| 116 |
-
{% else %}
|
| 117 |
-
{{ message.author }}:
|
| 118 |
-
{% endif %}
|
| 119 |
-
</strong> {{ message.content }}
|
| 120 |
-
</li>
|
| 121 |
-
{% endfor %}
|
| 122 |
</ul>
|
| 123 |
|
| 124 |
<h2>Pending LLM Messages for Approval</h2>
|
|
|
|
|
|
|
|
|
|
| 125 |
<ul class="pending-message-list">
|
| 126 |
{% for message in pending_messages %}
|
| 127 |
<li class="pending-message">
|
|
|
|
| 8 |
|
| 9 |
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
| 10 |
<script>
|
| 11 |
+
let agent_order = ["0", "1", "2"]; // Default agent order
|
| 12 |
+
|
| 13 |
+
// Function to fetch pending LLM messages
|
| 14 |
function fetchPendingMessages() {
|
|
|
|
| 15 |
$.getJSON('/get_pending_messages', function(data) {
|
| 16 |
+
let pendingMessageList = '';
|
|
|
|
| 17 |
if (data.length === 0) {
|
| 18 |
+
pendingMessageList = "<li>No pending messages</li>";
|
| 19 |
+
} else {
|
| 20 |
+
data.forEach(function(message, index) {
|
| 21 |
+
pendingMessageList += `
|
| 22 |
+
<li class="pending-message">
|
| 23 |
+
<p>${message.content} (Author: ${message.author})</p>
|
| 24 |
+
<div class="button-container">
|
| 25 |
+
<form action="/admin_dashboard" method="POST" style="display: inline;">
|
| 26 |
+
<input type="hidden" name="message_id" value="${index}">
|
| 27 |
+
<button type="submit" name="action" value="approve" class="button approve">Approve</button>
|
| 28 |
+
</form>
|
| 29 |
+
<form action="/admin_dashboard" method="POST" style="display: inline;">
|
| 30 |
+
<input type="hidden" name="message_id" value="${index}">
|
| 31 |
+
<button type="submit" name="action" value="delete" class="button delete">Delete</button>
|
| 32 |
+
</form>
|
| 33 |
+
</div>
|
| 34 |
+
</li>`;
|
| 35 |
+
});
|
| 36 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
$('#pending-message-list').html(pendingMessageList);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
});
|
| 39 |
}
|
| 40 |
+
|
| 41 |
+
// Function to fetch both message history and pending LLM messages
|
| 42 |
+
function fetchMessageHistoryAndPendingMessages() {
|
| 43 |
+
// Fetch message history
|
| 44 |
$.getJSON('/get_message_history', function(data) {
|
| 45 |
let messageHistory = '';
|
| 46 |
data.forEach(function(message) {
|
|
|
|
| 62 |
|
| 63 |
$('#message-history').html(messageHistory);
|
| 64 |
});
|
| 65 |
+
|
| 66 |
+
// Fetch pending LLM messages for approval
|
| 67 |
+
fetchPendingMessages(); // Fetch pending messages as part of message history update
|
| 68 |
}
|
| 69 |
|
|
|
|
| 70 |
// Function to fetch agent order immediately
|
| 71 |
function fetchAgentOrder() {
|
| 72 |
$.getJSON('/get_agent_order', function(agentData) {
|
|
|
|
| 75 |
});
|
| 76 |
}
|
| 77 |
|
| 78 |
+
// Add event listener for refresh button
|
| 79 |
+
$(document).ready(function() {
|
| 80 |
+
$('#refresh-pending-messages-btn').on('click', function() {
|
| 81 |
+
fetchPendingMessages(); // Trigger fetching pending messages on button click
|
| 82 |
+
});
|
| 83 |
+
});
|
| 84 |
+
|
| 85 |
// Poll the server every 1 second to update the message history and pending messages
|
| 86 |
// Fetch the agent order and then the message history every 2 seconds
|
| 87 |
setInterval(function() {
|
| 88 |
fetchAgentOrder(); // Fetch the dynamic agent order
|
| 89 |
+
fetchMessageHistoryAndPendingMessages(); // Fetch both message history and pending messages
|
|
|
|
| 90 |
}, 1000);
|
| 91 |
</script>
|
| 92 |
</head>
|
| 93 |
+
|
| 94 |
<body>
|
| 95 |
<div class="container admin-dashboard-container">
|
| 96 |
<h2>Send a Message to the User</h2>
|
|
|
|
| 104 |
|
| 105 |
<h2>Message History</h2>
|
| 106 |
<ul class="message-history" id="message-history">
|
| 107 |
+
<!-- Message history will be displayed here -->
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
</ul>
|
| 109 |
|
| 110 |
<h2>Pending LLM Messages for Approval</h2>
|
| 111 |
+
<form method="POST" action="/admin_dashboard">
|
| 112 |
+
<button type="submit" class="button">Refresh LLM Messages</button>
|
| 113 |
+
</form>
|
| 114 |
<ul class="pending-message-list">
|
| 115 |
{% for message in pending_messages %}
|
| 116 |
<li class="pending-message">
|
app/templates/dashboard.html
CHANGED
|
@@ -8,7 +8,7 @@
|
|
| 8 |
|
| 9 |
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
| 10 |
<script>
|
| 11 |
-
let agent_order = ["
|
| 12 |
|
| 13 |
// Function to fetch and update the message history and agent order
|
| 14 |
function fetchMessageHistory() {
|
|
@@ -52,12 +52,16 @@
|
|
| 52 |
|
| 53 |
// Submit the message via AJAX
|
| 54 |
$.post('/dashboard', { message: message }, function() {
|
|
|
|
|
|
|
| 55 |
// After submitting, immediately fetch the latest agent order
|
| 56 |
fetchAgentOrder();
|
| 57 |
|
| 58 |
// Also fetch the latest message history immediately
|
| 59 |
fetchMessageHistory();
|
| 60 |
-
|
|
|
|
|
|
|
| 61 |
// After submitting, you can trigger an immediate refresh of pending messages
|
| 62 |
// by notifying the admin dashboard to refresh its pending messages section.
|
| 63 |
// Notify admin side (no need to fetch pending messages on the user side)
|
|
@@ -88,22 +92,7 @@
|
|
| 88 |
|
| 89 |
<h1>Berichtgeschiedenis</h1>
|
| 90 |
<ul id="message-list">
|
| 91 |
-
|
| 92 |
-
<li><strong>
|
| 93 |
-
{% if message.author == 'Admin' %}
|
| 94 |
-
Agent {{ agent_order[0] }}:
|
| 95 |
-
{% elif message.author == 'llm2' %}
|
| 96 |
-
Agent {{ agent_order[1] }}:
|
| 97 |
-
{% elif message.author == 'llm3' %}
|
| 98 |
-
Agent{{ agent_order[2] }}:
|
| 99 |
-
{% elif message.author == 'User' %}
|
| 100 |
-
Jij:
|
| 101 |
-
{% else %}
|
| 102 |
-
{{ message.author }}:
|
| 103 |
-
{% endif %}
|
| 104 |
-
</strong> {{ message.content }}
|
| 105 |
-
</li>
|
| 106 |
-
{% endfor %}
|
| 107 |
</ul>
|
| 108 |
</div>
|
| 109 |
</body>
|
|
|
|
| 8 |
|
| 9 |
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
| 10 |
<script>
|
| 11 |
+
let agent_order = ["0", "1", "2"]; // Default agent order
|
| 12 |
|
| 13 |
// Function to fetch and update the message history and agent order
|
| 14 |
function fetchMessageHistory() {
|
|
|
|
| 52 |
|
| 53 |
// Submit the message via AJAX
|
| 54 |
$.post('/dashboard', { message: message }, function() {
|
| 55 |
+
console.log('User message submitted');
|
| 56 |
+
|
| 57 |
// After submitting, immediately fetch the latest agent order
|
| 58 |
fetchAgentOrder();
|
| 59 |
|
| 60 |
// Also fetch the latest message history immediately
|
| 61 |
fetchMessageHistory();
|
| 62 |
+
|
| 63 |
+
// This will notify the admin side to refresh pending messages
|
| 64 |
+
fetchPendingMessages();
|
| 65 |
// After submitting, you can trigger an immediate refresh of pending messages
|
| 66 |
// by notifying the admin dashboard to refresh its pending messages section.
|
| 67 |
// Notify admin side (no need to fetch pending messages on the user side)
|
|
|
|
| 92 |
|
| 93 |
<h1>Berichtgeschiedenis</h1>
|
| 94 |
<ul id="message-list">
|
| 95 |
+
<!-- Message history will be dynamically updated here -->
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
</ul>
|
| 97 |
</div>
|
| 98 |
</body>
|