fix show follow up responses

This commit is contained in:
2025-03-02 18:28:49 +00:00
parent dc5e2ef7c2
commit 7c20220c2f
2 changed files with 33 additions and 9 deletions

View File

@@ -256,6 +256,22 @@ document.addEventListener('DOMContentLoaded', function() {
continue;
}
// Handle follow-up response event
if (parsed.event === 'follow_up_response' && parsed.content) {
console.log('Received follow-up response');
// Add this follow-up response to message history
messageHistory.push({
role: 'assistant',
content: parsed.content
});
// Create a new message div for the follow-up response
// The addMessage function already handles markdown rendering
addMessage(parsed.content, false);
continue;
}
// Handle the complete response event
if (parsed.event === 'complete_response') {
console.log('Received complete response from backend');

View File

@@ -136,7 +136,9 @@ class WingmanView(AppBuilderBaseView):
logger.info("<<< COMPLETE RESPONSE END")
# Check for tool calls and make follow-up if needed
if client.provider.has_tool_calls(streaming_response):
has_tool_calls = client.provider.has_tool_calls(streaming_response)
logger.info(f"Has tool calls: {has_tool_calls}")
if has_tool_calls:
# Signal tool processing start - frontend should disable send button
yield f"data: {json.dumps({'event': 'tool_processing_start'})}\n\n"
@@ -152,13 +154,19 @@ class WingmanView(AppBuilderBaseView):
streaming_response, data["messages"], data["model"], data["temperature"], data["max_tokens"], cookie=cookie, stream=True
)
# Stream the follow-up response
# Collect the follow-up response
follow_up_complete_response = ""
for chunk in follow_up_response:
if chunk:
follow_up_complete_response += chunk
# logger.info(f"Yielding chunk to frontend: {chunk[:50]}...")
yield f"data: {chunk}\n\n"
# Send the follow-up response as a single event
if follow_up_complete_response:
follow_up_event = json.dumps({'event': 'follow_up_response', 'content': follow_up_complete_response})
logger.info(f"Follow-up event created with length: {len(follow_up_event)}")
data_line = f"data: {follow_up_event}\n\n"
logger.info(f"Yielding data line with length: {len(data_line)}")
yield data_line
# Log the complete follow-up response
logger.info("FOLLOW-UP RESPONSE START >>>")