-
Notifications
You must be signed in to change notification settings - Fork 479
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: test file and initial test for ai_tutor_interaction_controller #56361
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
54dc631
test file and initial test for ai_tutor_interaction_controller
Erin007 7d138b1
added three tests
kakiha11 302c671
Added an additional test for invalid status
kakiha11 946aa25
Fixed the invalid status test to have only an invalid status and upda…
kakiha11 fe71f17
Merge branch 'eb-write-to-ai-tutor-interactions' into ka-ai-tutor-int…
Erin007 1111581
standardize and share status and tutor type across front-end, back-en…
Erin007 345fb77
fix merge conflict TutorTypes -> TutorType
Erin007 c1bf962
Added in project back level tests and included validation & compilati…
kakiha11 24ae99e
check that project_id and project_version_id are being correctly set
Erin007 fbe4cf1
Merge branch 'eb-write-to-ai-tutor-interactions' into ka-ai-tutor-int…
Erin007 7706cfe
empty, kicking off Drone build
Erin007 192c4f9
appease linter
Erin007 e4a3b73
ruby linting
Erin007 File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
129 changes: 129 additions & 0 deletions
129
dashboard/test/controllers/ai_tutor_interactions_controller_test.rb
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
require 'test_helper' | ||
|
||
class AiTutorInteractionsControllerTest < ActionController::TestCase | ||
setup do | ||
@student_with_ai_tutor_access = create :student_with_ai_tutor_access | ||
@student = create :student | ||
end | ||
|
||
test "create AI Tutor Interaction with valid params" do | ||
sign_in @student_with_ai_tutor_access | ||
assert_creates(AiTutorInteraction) do | ||
post :create, params: { | ||
level_id: 1234, | ||
script_id: 987, | ||
type: SharedConstants::AI_TUTOR_TYPES[:GENERAL_CHAT], | ||
prompt: "Can you help me?", | ||
status: SharedConstants::AI_TUTOR_INTERACTION_SAVE_STATUS[:OK], | ||
ai_response: "Yes, I can help." | ||
} | ||
end | ||
end | ||
|
||
test "student without access can not create AI Tutor Interaction" do | ||
sign_in @student | ||
assert_does_not_create(AiTutorInteraction) do | ||
post :create, params: { | ||
level_id: 5678, | ||
script_id: 246, | ||
type: SharedConstants::AI_TUTOR_TYPES[:GENERAL_CHAT], | ||
prompt: "Can you help me?", | ||
status: SharedConstants::AI_TUTOR_INTERACTION_SAVE_STATUS[:OK], | ||
ai_response: "Yes, I can help." | ||
} | ||
end | ||
assert_response :forbidden | ||
end | ||
|
||
test "does not create AI Tutor Interaction with invalid type param" do | ||
sign_in @student_with_ai_tutor_access | ||
assert_does_not_create(AiTutorInteraction) do | ||
post :create, params: { | ||
level_id: 1234, | ||
script_id: 987, | ||
type: "trash can", | ||
prompt: "Can you help me?", | ||
status: SharedConstants::AI_TUTOR_INTERACTION_SAVE_STATUS[:OK], | ||
ai_response: "Yes, I can help." | ||
} | ||
end | ||
assert_response :not_acceptable | ||
assert_includes(@response.body, "There was an error creating a new AiTutorInteraction.") | ||
end | ||
|
||
test "does not create AI Tutor Interaction with invalid status param" do | ||
sign_in @student_with_ai_tutor_access | ||
assert_does_not_create(AiTutorInteraction) do | ||
post :create, params: { | ||
level_id: 1234, | ||
script_id: 987, | ||
type: SharedConstants::AI_TUTOR_TYPES[:GENERAL_CHAT], | ||
prompt: "Can you help me?", | ||
status: "broken", | ||
ai_response: "Yes, I can help." | ||
} | ||
end | ||
assert_response :not_acceptable | ||
assert_includes(@response.body, "Staus is unacceptable") | ||
end | ||
|
||
test "create AI Tutor Interaction for project backed level with valid params" do | ||
sign_in @student_with_ai_tutor_access | ||
@level = create(:level, :with_script) | ||
assert_creates(AiTutorInteraction) do | ||
post :create, params: { | ||
level_id: @level.id, | ||
script_id: @level.script_levels.first.script.id, | ||
type: SharedConstants::AI_TUTOR_TYPES[:COMPILATION], | ||
prompt: "Can you help me?", | ||
status: SharedConstants::AI_TUTOR_INTERACTION_SAVE_STATUS[:PROFANITY], | ||
ai_response: "Yes, I can help.", | ||
isProjectBacked: true | ||
} | ||
end | ||
end | ||
|
||
test "create AI Tutor Interaction for project backed level in lesson with lesson group with valid params" do | ||
sign_in @student_with_ai_tutor_access | ||
@lesson = create(:lesson, :with_lesson_group) | ||
@level = create(:level) | ||
@script_level = create :script_level, script: @lesson.script, lesson: @lesson, levels: [@level] | ||
@fake_ip = '127.0.0.1' | ||
fake_version_id = "fake-version-id" | ||
@storage_id = create_storage_id_for_user(@student_with_ai_tutor_access.id) | ||
channel_token = ChannelToken.find_or_create_channel_token(@script_level.level, @fake_ip, @storage_id, @script_level.script_id) | ||
@channel_id = channel_token.channel | ||
|
||
# Don't actually talk to S3 when running SourceBucket.new | ||
AWS::S3.stubs :create_client | ||
stub_project_source_data(@channel_id) | ||
_, @project_id = storage_decrypt_channel_id(@channel_id) | ||
@version_id = "fake-version-id" | ||
|
||
assert_creates(AiTutorInteraction) do | ||
post :create, params: { | ||
level_id: @script_level.levels.first.id, | ||
script_id: @script_level.script.id, | ||
type: SharedConstants::AI_TUTOR_TYPES[:VALIDATION], | ||
prompt: "Why is my test failing?", | ||
status: SharedConstants::AI_TUTOR_INTERACTION_SAVE_STATUS[:OK], | ||
ai_response: "Because your code is wrong.", | ||
isProjectBacked: true | ||
} | ||
created_ai_tutor_interaction = AiTutorInteraction.last | ||
assert created_ai_tutor_interaction.project_id == @project_id.to_s | ||
assert created_ai_tutor_interaction.project_version_id == fake_version_id | ||
end | ||
end | ||
|
||
private def stub_project_source_data(channel_id, code: 'fake-code', version_id: 'fake-version-id') | ||
fake_main_json = {source: code}.to_json | ||
fake_source_data = { | ||
status: 'FOUND', | ||
body: StringIO.new(fake_main_json), | ||
version_id: version_id, | ||
last_modified: DateTime.now | ||
} | ||
SourceBucket.any_instance.stubs(:get).with(channel_id, "main.json").returns(fake_source_data) | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -659,4 +659,24 @@ module SharedConstants | |
# We should always specify a version for the LLM so the results don't unexpectedly change. | ||
# reference: https://platform.openai.com/docs/models/gpt-3-5 | ||
AI_TUTOR_CHAT_MODEL_VERISON = 'gpt-3.5-turbo-1106' | ||
|
||
# These reflect the 'status' of an AI Tutor Interaction | ||
AI_TUTOR_INTERACTION_SAVE_STATUS = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's cool we can share an object between ruby and typescript! |
||
ERROR: 'error', | ||
PERSONAL: 'personal', | ||
PROFANITY: 'profanity', | ||
INAPPROPRIATE: 'inappropriate', | ||
OK: 'ok', | ||
UNKNOWN: 'unknown', | ||
EMAIL: 'email', | ||
ADDRESS: 'address', | ||
PHONE: 'phone', | ||
}.freeze | ||
|
||
# These are the types of assistance AI Tutor can provide | ||
AI_TUTOR_TYPES = { | ||
COMPILATION: 'compilation', | ||
VALIDATION: 'validation', | ||
GENERAL_CHAT: 'general_chat', | ||
}.freeze | ||
end |
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.
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.
nit: use
@cdo...
syntax for import