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
[AI Tutor] CT-562: Add s3 system prompt #58486
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple questions, otherwise looks good
end | ||
|
||
private def read_file_from_s3(key_path) | ||
if [:development, :test].include?(rack_env) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this to make local testing easier? Why do we need this for test
too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Locally, this is so I can try out an updated system prompt without replacing the contents in production. (AI TA might have needed this in test for their test suite, but we don't.) I'm removing the :test env here for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice catch and good call! the :test
part looks like a mistake on our end because it would have no effect in automated testing and would potentially break running our tests locally.
return File.read(local_path) | ||
end | ||
end | ||
s3_client.get_object(bucket: S3_AI_BUCKET, key: key_path).body.read |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will this cache the response? I'm guessing the system prompt won't change that much?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a thread relevant to this comment and the one above here: https://codedotorg.slack.com/archives/C051P2V2RN0/p1715274926003069?thread_ts=1715274404.871189&cid=C051P2V2RN0
I copied the dev/test logic from Teacher Tools. I originally had it cached and then disabled it because I was troubleshooting unrelated test failures that mentioned a cache, and Dave said it shouldn't be pilot-blocking. If it's okay with you, I'll reenable the caching, assuming it passes Drone. No strong feelings on the dev/test thing -- though it probably makes sense to disable it for test if we don't know the application :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great job on thorough test coverage!
end | ||
|
||
private def read_file_from_s3(key_path) | ||
if [:development, :test].include?(rack_env) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice catch and good call! the :test
part looks like a mistake on our end because it would have no effect in automated testing and would potentially break running our tests locally.
# Post request without a messages param returns a bad request | ||
test_user_gets_response_for :chat_completion, | ||
name: "no_messages_test", | ||
user: :ai_tutor_access, | ||
method: :post, | ||
params: {}, | ||
response: :bad_request | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤩
@molly-moen @davidsbailey Thoughts on this approach to caching? https://github.com/code-dot-org/code-dot-org/pull/58486/files/ff7859efb863474271ec287dfd9a66127a5b2a1a..6daa4f98764fed7b707937ceb5fe834ec799e2f2 I disabled it in dev because I feel like caching causes more problems than it solves locally, but the risk is this logic is only unit-tested before it hits test and prod. Should I be caching in the test environment? 🤔 Does it matter? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉
@@ -72,14 +72,27 @@ def add_content_to_system_prompt(system_prompt, level_instructions, test_file_co | |||
end | |||
|
|||
private def read_file_from_s3(key_path) | |||
if [:development, :test].include?(rack_env) | |||
cache_key = "s3_file_#{key_path}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ebeastlake I don't know much about caching besides "we should probably do it here". It makes sense to me to run it on prod and maybe test too? I don't see a downside to running caching on test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM after addressing comments
@@ -72,14 +72,27 @@ def add_content_to_system_prompt(system_prompt, level_instructions, test_file_co | |||
end | |||
|
|||
private def read_file_from_s3(key_path) | |||
if [:development, :test].include?(rack_env) | |||
cache_key = "s3_file_#{key_path}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since we don't know how else the shared cache is being used, I would suggest including the bucket name in the cache key.
We want to keep our system prompt hidden from the user. I moved it to the
cdo-ai/tutor
bucket in S3. It now gets loaded server-side and appended to the conversation history before it gets sent to OpenAI.So currently the flow is:
☝️ We might want to modify this at some point, but since this is a last-minute change, I wanted to keep it as close to the original implementation as possible.
Other changes in this PR:
Links
Jira ticket: https://codedotorg.atlassian.net/browse/CT-562
Testing story
Added unit tests for:
I tested manually that the code compilation and validation cases were still working as expected.
And also that error states are being handled as expected (by blocking network requests from the console).
I also tested that the questionable answers in the AI Tutor Bug Bash doc are all resolved by the new system prompt, see comments here: https://docs.google.com/document/d/1PAT43dP4lhuhhecQIaeb2ZnsH8dzU-1UaDwA-N4QAC8/edit#heading=h.kgu6m7hz2xke
Deployment strategy
Follow-up work
I followed a file-up ticket to capture adding eyes tests for AI Tutor UI: https://codedotorg.atlassian.net/browse/CT-571
PR Checklist: