Fixed error 1 (openAI title sanitization) and added unit tests#466
Draft
amahuli03 wants to merge 1 commit intoCodeForPhilly:developfrom
Draft
Fixed error 1 (openAI title sanitization) and added unit tests#466amahuli03 wants to merge 1 commit intoCodeForPhilly:developfrom
amahuli03 wants to merge 1 commit intoCodeForPhilly:developfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes the
/v1/api/uploadFileendpoint failure that occurs when title extraction falls back to OpenAI. OpenAI sometimes returns titles wrapped in quotes (ex: '"Updated CANMAT/ISBD Guidelines..."'). The raw response is saved without sanitization, which caused a 400 error in the reported logs. This PR strips wrapping quotes and whitespace from OpenAI-generated titles before returning.This PR also truncates titles to 255 characters so the title is guaranteed to fit in the
CharFieldsize limit. This is just an extra safeguard in the case where OpenAI doesn't respect the 256 character limit specified in the prompt.Related Issue
Addresses part of #390
Manual Tests
(I'm not able to manually test right now, looking for help getting my local dev environment and workflow set up)
Automated Tests
Added 2 new unit tests to
test_title.py:test_strips_quotes_from_openai_titleverifies wrapping quotes are removed from OpenAI-generated titlestest_truncates_long_openai_titleverifies titles exceeding 255 characters are truncatedAll tests passing (4 existing + 2 new)
Reviewers
@sahilds1
Notes
Also added some more logs to the error handler in
views.pyso errors include full traceback.This only addresses the first error from the original issue. The second error is being caused by a separate bug which I think has to do with the upload component in
UploadFile.tsxwhere we're settingContent-Type: multipart/form-databut not providing a boundary parameter. Needs further investigation and manual testing.(This is a separate issue) When I tried uploading files manually in my local dev environment, I got
Unauthorized: /api/v1/api/uploadFilewhich is not a valid route, right? Has anyone seen this issue?