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

Added a level-specific prompt field to AI Tutor section of levelbuilder #57051

Merged
merged 19 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions apps/src/aiTutor/redux/aiTutorRedux.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ export const askAITutor = createAsyncThunk(
} else {
systemPrompt = generalChatSystemPrompt;
}
if (state.aiTutor.level?.levelSpecificPrompt) {
systemPrompt += state.aiTutor.level?.levelSpecificPrompt;
}
kakiha11 marked this conversation as resolved.
Show resolved Hide resolved

const storedMessages = state.aiTutor.chatMessages;

Expand Down
1 change: 1 addition & 0 deletions apps/src/aiTutor/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export type Level = {
hasValidation: boolean;
isAssessment: boolean;
isProjectBacked: boolean;
levelSpecificPrompt: string;
kakiha11 marked this conversation as resolved.
Show resolved Hide resolved
};

export interface ChatContext {
Expand Down
11 changes: 9 additions & 2 deletions apps/src/sites/studio/pages/levels/show.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,21 @@ function initPage() {

if (hasScriptData('script[data-aitutordata]')) {
const aiTutorData = getScriptData('aitutordata');
const {levelId, type, hasValidation, isAssessment, isProjectBacked} =
aiTutorData;
const {
levelId,
type,
hasValidation,
isAssessment,
isProjectBacked,
levelSpecificPrompt,
} = aiTutorData;
const level = {
id: levelId,
type: type,
hasValidation: hasValidation,
isAssessment: isAssessment,
isProjectBacked: isProjectBacked,
levelSpecificPrompt,
kakiha11 marked this conversation as resolved.
Show resolved Hide resolved
};
getStore().dispatch(setLevel(level));
getStore().dispatch(setScriptId(aiTutorData.scriptId));
Expand Down
1 change: 1 addition & 0 deletions dashboard/app/models/levels/level.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ class Level < ApplicationRecord
thumbnail_url
start_libraries
ai_tutor_available
ai_tutor_level_specific_prompt
)

# Fix STI routing http://stackoverflow.com/a/9463495
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
%h1.control-legend{data: {toggle: "collapse", target: "#ai_tutor"}}
AI Tutor
#ai_tutor.in.collapse
.field
= render partial: 'levels/editors/fields/checkboxes', locals: {f: f, field_name: :ai_tutor_available, description: "AI Tutor Available"}

= f.label :ai_tutor_level_specific_prompt, 'Level-Specific Prompt'
%p Prompt used to specify the behavior of AI Tutor on a per level basis.
= f.text_area :ai_tutor_level_specific_prompt, placeholder: 'Write your level-specific prompt here. If left blank, this level will use the default system prompt.', rows: 4, class:"input-block-level"
kakiha11 marked this conversation as resolved.
Show resolved Hide resolved

= render partial: 'levels/editors/fields/checkboxes', locals: {f: f, field_name: :ai_tutor_available, description: "Make AI Tutor Available"}

kakiha11 marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion dashboard/app/views/levels/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

- if @script_level
- level_data = { redirect_script_url: @redirect_unit_url, script_name: @script_level.script&.name, course_name: @script_level.script&.unit_group&.name, level_name: @level.name, tts_autoplay_enabled: @tts_autoplay_enabled, code_review_enabled: @code_review_enabled_for_level, show_unversioned_redirect_warning: @show_unversioned_redirect_warning}
- ai_tutor_data = {levelId: @level&.id, scriptId: @script_level.script&.id, type: @level&.type, hasValidation: !!@level&.properties["encrypted_validation"], isAssessment: @script_level&.assessment, isProjectBacked: !!@level&.properties["project_template_level_name"]}
- ai_tutor_data = {levelId: @level&.id, scriptId: @script_level.script&.id, type: @level&.type, hasValidation: !!@level&.properties["encrypted_validation"], isAssessment: @script_level&.assessment, isProjectBacked: !!@level&.properties["project_template_level_name"], levelSpecificPrompt: @level&.ai_tutor_level_specific_prompt}
%link{href: asset_path('css/levels.css'), rel: 'stylesheet', type: 'text/css'}
%script{ src: webpack_asset_path('js/levels/show.js'), data: { aiTutorData: ai_tutor_data.to_json, level: level_data.to_json, rubricData: @rubric_data&.to_json }}
-# Mount point for RedirectDialog React component.
Expand Down