diff --git a/backend/openedx_ai_extensions/workflows/orchestrators.py b/backend/openedx_ai_extensions/workflows/orchestrators.py index 0261ce8..772fe33 100644 --- a/backend/openedx_ai_extensions/workflows/orchestrators.py +++ b/backend/openedx_ai_extensions/workflows/orchestrators.py @@ -245,7 +245,7 @@ def run(self, input_data): # --- 7. Return Structured Non-Streaming Result --- # If execution reaches this point, we have a successful, non-streaming result (Dict). response_data = { - 'response': llm_result.get('response', 'No response available'), + 'response': llm_result.get('response') or 'No response available', 'status': 'completed', 'metadata': { 'tokens_used': llm_result.get('tokens_used'), @@ -451,7 +451,7 @@ def lazy_load_chat_history(self, input_data): } return { - "response": result.get("response", "{}"), + "response": result.get("response") or "{}", "status": "completed", } @@ -521,7 +521,7 @@ def run(self, input_data): "status": "SubmissionProcessor error", } return { - "response": history_result.get("response", "No response available"), + "response": history_result.get("response") or "No response available", "status": "completed", } @@ -568,7 +568,7 @@ def run(self, input_data): # --- BRANCH C: Handle Non-Streaming (Standard) --- messages = [ - {"role": "assistant", "content": llm_result.get("response", "")}, + {"role": "assistant", "content": llm_result.get("response") or ""}, ] if input_data: messages.insert(0, {"role": "user", "content": input_data}) @@ -591,7 +591,7 @@ def run(self, input_data): # 4. Return result return { - "response": llm_result.get("response", "No response available"), + "response": llm_result.get("response") or "No response available", "status": "completed", "metadata": { "tokens_used": llm_result.get("tokens_used"), diff --git a/frontend/src/ConfigurableAIAssistance.jsx b/frontend/src/ConfigurableAIAssistance.jsx index 4158490..86ec4a9 100644 --- a/frontend/src/ConfigurableAIAssistance.jsx +++ b/frontend/src/ConfigurableAIAssistance.jsx @@ -22,6 +22,7 @@ import { AIEducatorLibraryAssistComponent, AIEducatorLibraryResponseComponent, } from './components'; +import { NO_RESPONSE_MSG } from './services/constants'; /** * Component Registry @@ -177,7 +178,7 @@ const ConfigurableAIAssistance = ({ } else if (data.error) { throw new Error(data.error); } else { - setResponse(JSON.stringify(data, null, 2)); + setResponse(NO_RESPONSE_MSG); setHasAsked(true); } diff --git a/frontend/src/GetAIAssistanceButton.jsx b/frontend/src/GetAIAssistanceButton.jsx index fae0058..f390335 100644 --- a/frontend/src/GetAIAssistanceButton.jsx +++ b/frontend/src/GetAIAssistanceButton.jsx @@ -13,6 +13,7 @@ import { AIRequestComponent, AIResponseComponent, } from './components'; +import { NO_RESPONSE_MSG } from './services/constants'; /** * Main AI Assistant Plugin Component @@ -81,7 +82,7 @@ const GetAIAssistanceButton = ({ throw new Error(data.error); } else { // If API returns something but in unexpected format, try to use it - setResponse(JSON.stringify(data, null, 2)); + setResponse(NO_RESPONSE_MSG); setHasAsked(true); } diff --git a/frontend/src/components/AIEducatorLibraryAssistComponent.jsx b/frontend/src/components/AIEducatorLibraryAssistComponent.jsx index 9ef7079..2ab5dec 100644 --- a/frontend/src/components/AIEducatorLibraryAssistComponent.jsx +++ b/frontend/src/components/AIEducatorLibraryAssistComponent.jsx @@ -11,6 +11,7 @@ import { AutoAwesome, Close } from '@openedx/paragon/icons'; import { getConfig } from '@edx/frontend-platform'; import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth'; import { callWorkflowService, prepareContextData } from '../services'; +import { NO_RESPONSE_MSG } from '../services/constants'; /** * AI Educator Library Assist Component @@ -207,7 +208,7 @@ const AIEducatorLibraryAssistComponent = ({ } else { // Immediate response const immediateResponse = data.response || data.message || data.content - || data.result || JSON.stringify(data, null, 2); + || data.result || NO_RESPONSE_MSG; setResponse(immediateResponse); } diff --git a/frontend/src/components/AISidebarResponse.jsx b/frontend/src/components/AISidebarResponse.jsx index 38bc1ba..98d3ac1 100644 --- a/frontend/src/components/AISidebarResponse.jsx +++ b/frontend/src/components/AISidebarResponse.jsx @@ -20,6 +20,7 @@ import { prepareContextData, formatErrorMessage, } from '../services'; +import { NO_RESPONSE_MSG } from '../services/constants'; /** * AI Sidebar Response Component @@ -414,7 +415,7 @@ const AISidebarResponse = ({ } else if (data.result) { aiResponse = data.result; } else { - aiResponse = JSON.stringify(data, null, 2); + aiResponse = NO_RESPONSE_MSG; } // Update the AI placeholder with the final response diff --git a/frontend/src/services/constants.js b/frontend/src/services/constants.js new file mode 100644 index 0000000..62e6d2d --- /dev/null +++ b/frontend/src/services/constants.js @@ -0,0 +1 @@ +export const NO_RESPONSE_MSG = 'No response available';