Skip to content

fix: correct params in llm api call#223

Merged
mraman-2U merged 5 commits into
mainfrom
krishatcher/xprt-1917-pass-convo-id-to-api-part2
Apr 27, 2026
Merged

fix: correct params in llm api call#223
mraman-2U merged 5 commits into
mainfrom
krishatcher/xprt-1917-pass-convo-id-to-api-part2

Conversation

@krishatcher
Copy link
Copy Markdown
Contributor

During validation of #222 in production, it was found that the Conversation-History-ID had been implemented based on outdated documentation. This change moves that value to the correct location based on the implementation within Xpert API Services today.

Move parameter into body and rename to align with expectation for Xpert API Services.
Copilot AI review requested due to automatic review settings April 24, 2026 18:06
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR corrects how the conversation history identifier is sent to the LLM backend by removing the outdated Conversation-History-ID header usage and instead including the identifier in the request body for the v2 API format, aligning with current Xpert API Services behavior.

Changes:

  • Remove Conversation-History-ID from request headers.
  • Add conversation_id to the v2 request body and update request-body construction to accept a conversation id.
  • Update conversation-id seed format to a stable JSON array string for deterministic UUID generation.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
learning_assistant/utils.py Moves conversation identifier from headers into the v2 body (conversation_id) and updates deterministic ID seeding format.
tests/test_utils.py Updates request-structure assertions to reflect header removal and new v2 body field.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/test_utils.py Outdated
Copilot AI review requested due to automatic review settings April 24, 2026 18:11
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 24, 2026

Coverage report

Click to see where and how coverage changed

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

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

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 70 to +76
if v2_endpoint_enabled():
response_body = {
'client_id': getattr(settings, 'CHAT_COMPLETION_CLIENT_ID', 'edx_olc_la'),
'system_message': prompt_template,
'messages': messages,
'external_id': str(user_id),
'conversation_id': convo_id,
Copy link

Copilot AI Apr 24, 2026

Choose a reason for hiding this comment

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

get_chat_response() selects the endpoint using v2_endpoint_enabled(), but create_request_body() also calls v2_endpoint_enabled() internally to choose the payload shape. If the waffle flag value changes between these calls (or behaves differently per call), the code can send a v2 payload to the v1 endpoint (or vice versa). Consider computing the v2-enabled boolean once in get_chat_response() and passing it into create_request_body() so endpoint selection and payload structure stay consistent.

Copilot uses AI. Check for mistakes.
Comment on lines +115 to +116
conversation_history_id = create_conversation_history_id(user_id, course_run_id)
body = create_request_body(prompt_template, message_list, user_id, conversation_history_id)
Copy link

Copilot AI Apr 24, 2026

Choose a reason for hiding this comment

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

create_request_body() now requires convo_id, but the v1 request body ignores it. This forces get_chat_response() to always compute a conversation id even when the v2 endpoint is disabled, and makes create_request_body() harder to reuse correctly. Consider making convo_id optional (e.g., defaulting to None) and only generating/passing it when building the v2 payload.

Copilot uses AI. Check for mistakes.
Comment thread tests/test_utils.py
Comment on lines +134 to +135
mock_convo_id_seed = json.dumps([str(self.user_id), str(self.course_id)], separators=(',', ':'))
mock_convo_hist_id = str(uuid.uuid5(uuid.NAMESPACE_URL, str(mock_convo_id_seed)))
Copy link

Copilot AI Apr 24, 2026

Choose a reason for hiding this comment

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

This test re-implements the conversation-id generation logic inline (json.dumps(...) + uuid.uuid5(...)). To avoid future drift from create_conversation_history_id() (which is part of what you’re validating), consider importing and calling create_conversation_history_id(self.user_id, self.course_id) here instead of duplicating the algorithm.

Copilot uses AI. Check for mistakes.
@mraman-2U mraman-2U merged commit f801e78 into main Apr 27, 2026
4 checks passed
@mraman-2U mraman-2U deleted the krishatcher/xprt-1917-pass-convo-id-to-api-part2 branch April 27, 2026 13:39
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