Skip to content

Commit

Permalink
fix: Swapped course id for course key
Browse files Browse the repository at this point in the history
  • Loading branch information
rijuma committed Oct 31, 2024
1 parent 6310393 commit 6106dc8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
7 changes: 4 additions & 3 deletions learning_assistant/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,9 @@ def post(self, request, course_run_id):
data={'detail': "Expects user role on last message."}
)

course_id = get_course_id(course_run_id)
user_id = request.user.id

if chat_history_enabled(course_id):
if chat_history_enabled(courserun_key):
save_chat_message(user_id, LearningAssistantMessage.USER_ROLE, new_user_message['content'])

serializer = MessageSerializer(data=message_list, many=True)
Expand All @@ -117,14 +116,16 @@ def post(self, request, course_run_id):
}
)

course_id = get_course_id(course_run_id)

template_string = getattr(settings, 'LEARNING_ASSISTANT_PROMPT_TEMPLATE', '')

prompt_template = render_prompt_template(
request, request.user.id, course_run_id, unit_id, course_id, template_string
)
status_code, message = get_chat_response(prompt_template, message_list)

if chat_history_enabled(course_id):
if chat_history_enabled(courserun_key):
save_chat_message(user_id, LearningAssistantMessage.ASSISTANT_ROLE, message['content'])

return Response(status=status_code, data=message)
Expand Down
12 changes: 7 additions & 5 deletions tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,13 @@ def test_chat_response_default(
test_unit_id = 'test-unit-id'

# TODO: Fix this...
# For some reason this only works the first time. The 2nd time (enabled_flag = False)
# Doesn't actually work since the mocked chat_history_enabled() will return False no matter what.
# Swap the order of the @ddt.data() above by: @ddt.data(False, True) and watch it fail.
# The value for enabled_flag is corrct on this scope, but the mocked method doesn't update.
# It even happens if we split the test cases into two different methods.
# For some reason this assignment only works the first iteration. The 2nd time onwards the return value is
# always falsy. Swap the order of the @ddt.data() above by: @ddt.data(False, True) to see it fail.
# I'm leaving it like this because we are testing the False return in the second iteration, but it's important
# to consider whenever this test needs to be updated.
# It even happens if we split the test cases into two different methods (instead of @ddt.data()), so there's
# probably some scoping issues in how the test is set up.
# Note: There's a similar test for LearningAssistantEnabledView in this file that works just fine.
mock_chat_history_enabled.return_value = enabled_flag

test_data = [
Expand Down

0 comments on commit 6106dc8

Please sign in to comment.