Spaces:
Running on Zero
Running on Zero
Siddharth Ravikumar commited on
Commit ·
e1b2f61
1
Parent(s): 0c2e108
fix: robust chat parsing and visibility fixes
Browse files- frontend/index.html +1 -1
- frontend/js/alt_app.js +28 -6
frontend/index.html
CHANGED
|
@@ -604,7 +604,7 @@
|
|
| 604 |
</div>
|
| 605 |
</div>
|
| 606 |
|
| 607 |
-
<script src="js/alt_app.js"></script>
|
| 608 |
</body>
|
| 609 |
|
| 610 |
</html>
|
|
|
|
| 604 |
</div>
|
| 605 |
</div>
|
| 606 |
|
| 607 |
+
<script src="js/alt_app.js?v=0317e"></script>
|
| 608 |
</body>
|
| 609 |
|
| 610 |
</html>
|
frontend/js/alt_app.js
CHANGED
|
@@ -952,16 +952,38 @@ async function sendChatMessage() {
|
|
| 952 |
|
| 953 |
// chat output expects: [updated_history, clean_input, currentSystemCtx]
|
| 954 |
const updatedHistory = responseData[0];
|
|
|
|
|
|
|
| 955 |
// Gradio 6.x messages format: [{role: "user", content: "..."}, {role: "assistant", content: "..."}]
|
| 956 |
-
|
| 957 |
-
|
| 958 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 959 |
chatHistory = updatedHistory;
|
| 960 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 961 |
chatContainer.innerHTML += `
|
| 962 |
-
<div class="chat-message assistant" style="text-align:left; margin:10px 0; max-width:
|
| 963 |
-
<i class="fa-solid fa-robot" style="margin-right:10px;"></i>
|
| 964 |
-
<
|
|
|
|
|
|
|
| 965 |
</div>
|
| 966 |
`;
|
| 967 |
chatContainer.scrollTop = chatContainer.scrollHeight;
|
|
|
|
| 952 |
|
| 953 |
// chat output expects: [updated_history, clean_input, currentSystemCtx]
|
| 954 |
const updatedHistory = responseData[0];
|
| 955 |
+
console.log('[Chat] Updated history:', JSON.stringify(updatedHistory));
|
| 956 |
+
|
| 957 |
// Gradio 6.x messages format: [{role: "user", content: "..."}, {role: "assistant", content: "..."}]
|
| 958 |
+
// Gradio 5.x messages format: [[user, assistant], [user, assistant]]
|
| 959 |
+
|
| 960 |
+
let lastBotMsg = '';
|
| 961 |
+
if (Array.isArray(updatedHistory) && updatedHistory.length > 0) {
|
| 962 |
+
const lastMsg = updatedHistory[updatedHistory.length - 1];
|
| 963 |
+
console.log('[Chat] Last message entry:', JSON.stringify(lastMsg));
|
| 964 |
+
|
| 965 |
+
if (lastMsg && typeof lastMsg === 'object' && lastMsg.role === 'assistant') {
|
| 966 |
+
lastBotMsg = lastMsg.content || '';
|
| 967 |
+
} else if (Array.isArray(lastMsg)) {
|
| 968 |
+
// tuple format [user, assistant]
|
| 969 |
+
lastBotMsg = lastMsg[1] || '';
|
| 970 |
+
}
|
| 971 |
+
}
|
| 972 |
+
|
| 973 |
+
console.log('[Chat] Extracted bot message:', lastBotMsg);
|
| 974 |
chatHistory = updatedHistory;
|
| 975 |
|
| 976 |
+
if (!lastBotMsg) {
|
| 977 |
+
console.warn('[Chat] Warning: Bot message is empty after extraction');
|
| 978 |
+
}
|
| 979 |
+
|
| 980 |
+
// Assistant Bubble
|
| 981 |
chatContainer.innerHTML += `
|
| 982 |
+
<div class="chat-message assistant" style="text-align:left; margin:10px 0; max-width:85%; display:flex; align-items:start;">
|
| 983 |
+
<i class="fa-solid fa-robot" style="margin-right:10px; margin-top:10px; color: var(--accent);"></i>
|
| 984 |
+
<div style="background:rgba(255,255,255,0.15); border:1px solid rgba(0,0,0,0.1); padding:10px 15px; border-radius:18px; color: #000; font-weight: 500; font-size: 0.95rem; line-height:1.5;">
|
| 985 |
+
${escHtml(lastBotMsg) || '<i style="color:red;">(Empty Response)</i>'}
|
| 986 |
+
</div>
|
| 987 |
</div>
|
| 988 |
`;
|
| 989 |
chatContainer.scrollTop = chatContainer.scrollHeight;
|