Skip to content

Commit ec8a515

Browse files
committed
fix: use session metadata instead of submissions to store educator collections
1 parent cfc3e21 commit ec8a515

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

backend/openedx_ai_extensions/workflows/orchestrators.py

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ def __init__(self, workflow):
8888
location_id=self.workflow.location_id,
8989
defaults={},
9090
)
91-
self.submission_processor = self._get_submission_processor()
9291

9392
def clear_session(self, _):
9493
self.session.delete()
@@ -97,10 +96,6 @@ def clear_session(self, _):
9796
"status": "session_cleared",
9897
}
9998

100-
def get_submission(self):
101-
"""Retrieve the current submission associated with the user session."""
102-
return self.submission_processor.get_submission()
103-
10499
def _get_submission_processor(self):
105100
return SubmissionProcessor(
106101
self.config.processor_config, self.session
@@ -115,9 +110,9 @@ class EducatorAssistantOrchestrator(SessionBasedOrchestrator):
115110

116111
def get_current_session_response(self, _):
117112
"""Retrieve the current session's LLM response."""
118-
submission = self.get_submission()
119-
if submission and submission.get("answer"):
120-
return {"response": submission["answer"]["collection_url"]}
113+
metadata = self.session.metadata or {}
114+
if metadata and "collection_url" in metadata:
115+
return {"response": metadata["collection_url"]}
121116
return {"response": None}
122117

123118
def run(self, input_data):
@@ -159,13 +154,13 @@ def run(self, input_data):
159154
items=llm_result["response"]["items"]
160155
)
161156

162-
data = {
157+
metadata = {
163158
"library_id": lib_key_str,
164159
"collection_url": f"authoring/library/{lib_key_str}/collection/{collection_key}",
165160
"collection_id": collection_key,
166161
}
167-
self.submission_processor.update_submission(data)
168-
162+
self.session.metadata = metadata
163+
self.session.save(update_fields=["metadata"])
169164
# 3. Return result
170165
return {
171166
'response': f"authoring/library/{lib_key_str}/collection/{collection_key}",
@@ -200,7 +195,8 @@ def lazy_load_chat_history(self, input_data):
200195
elif isinstance(input_data, int):
201196
current_messages_count = input_data
202197

203-
result = self.submission_processor.get_previous_messages(current_messages_count)
198+
submission_processor = self._get_submission_processor()
199+
result = submission_processor.get_previous_messages(current_messages_count)
204200

205201
if "error" in result:
206202
return {
@@ -218,10 +214,11 @@ def run(self, input_data):
218214
"course_id": self.workflow.course_id,
219215
"extra_context": self.workflow.extra_context,
220216
}
217+
submission_processor = self._get_submission_processor()
221218

222219
# 1. get chat history if there is user session
223220
if self.session and self.session.local_submission_id and not input_data:
224-
history_result = self.submission_processor.process(context)
221+
history_result = submission_processor.process(context)
225222

226223
if "error" in history_result:
227224
return {
@@ -249,7 +246,7 @@ def run(self, input_data):
249246
context=str(content_result), input_data=input_data
250247
)
251248

252-
self.submission_processor.update_chat_submission(llm_result.get("response"), input_data)
249+
submission_processor.update_chat_submission(llm_result.get("response"), input_data)
253250

254251
if "error" in llm_result:
255252
return {"error": llm_result["error"], "status": "ResponsesProcessor error"}

0 commit comments

Comments
 (0)