Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: gate use of v2 endpoint with waffle flag #152

Merged
merged 2 commits into from
Jan 8, 2025

Conversation

alangsto
Copy link
Member

@alangsto alangsto commented Jan 6, 2025

COSMO-620

The Xpert platform team has released a new v2 endpoint for processing messages. This PR gates use of the v2 endpoint by a new waffle flag.

I also cleaned up some code related to an unused API key and an unused waffle flag related to course content.



def chat_history_enabled(course_key):
def v2_endpoint_enabled():
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not make this a course waffle flag as I don't believe we need a course by course roll out.

Copy link

github-actions bot commented Jan 6, 2025

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  learning_assistant
  __init__.py
  toggles.py 43
  utils.py
Project Total  

This report was generated by python-coverage-comment-action

Copy link
Member

@varshamenon4 varshamenon4 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great so far! Just a couple of clarifying questions and nits.

completion_endpoint = getattr(settings, 'CHAT_COMPLETION_API', None)
completion_endpoint_key = getattr(settings, 'CHAT_COMPLETION_API_KEY', None)
if completion_endpoint and completion_endpoint_key:
headers = {'Content-Type': 'application/json', 'x-api-key': completion_endpoint_key}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: is there no longer the need for an api key with the new endpoint?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's not a need for an api key with the current endpoint! It was added at one point because the Xpert platform team was going to require it, but then it was never enforced.

}

if v2_endpoint_enabled():
response_body = {
'client_id': getattr(settings, 'CHAT_COMPLETION_CLIENT_ID', 'edx_olc_la'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: what is the 'edx_olc_la'? Is there a reason why this is hardcoded rather than added as a setting?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is added as a setting, the string is just the default if no setting is found

@@ -126,18 +145,18 @@ def test_message_list_reduced(self):
"""
# pass in copy of list, as it is modified as part of the reduction
reduced_message_list = get_reduced_message_list(self.prompt_template, self.message_list)
self.assertEqual(len(reduced_message_list), 2)
self.assertEqual(len(reduced_message_list), 1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: might be missing this in the implementation but can you clarify why the length goes down by 1 for this assert and the assert below?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I modified what get_reduced_message_list returns, so that it doesn't include the system prompt.

@@ -14,6 +14,10 @@ Change Log
Unreleased
**********

4.6.4 - 2025-01-06
******************
* Gate use of the Xpert platform v2 endpoint with a waffle flag.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: would using the v2 endpoint justify considering this a minor release than a patch? So 4.7.0 instead of 4.6.4? Sort of a nit but I wasn't sure how big of a change this would represent api-wise.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh fair point! It's not breaking, but I could see a minor release being more appropriate.

system_message = {'role': 'system', 'content': prompt_template}

return [system_message] + new_message_list
return new_message_list
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you decide to remove the system message?
Is this a change that is going to affect edX Xpert LA UI?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I modified this function to allow for the two different request bodies in the v1 vs v2 version of the endpoint. The system message is still included in the request (see

response_body = {
'message_list': [{'role': 'system', 'content': prompt_template}] + messages,
}
if v2_endpoint_enabled():
response_body = {
'client_id': getattr(settings, 'CHAT_COMPLETION_CLIENT_ID', 'edx_olc_la'),
'system_message': prompt_template,
'messages': messages,
}
)

@alangsto alangsto marked this pull request as ready for review January 7, 2025 18:33
@alangsto alangsto merged commit 93e9d3a into main Jan 8, 2025
4 checks passed
@alangsto alangsto deleted the alangsto/update_xpert_endpoint branch January 8, 2025 13:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants