Update AI Tutor in Python Lab#73297
Draft
fisher-alice wants to merge 16 commits into
Draft
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR wires AI Tutor prompt settings into Python Lab (and updates Web Lab 2’s levelbuilder prompt settings integration), adding Python Lab–specific prompt assets and structured response handling, while also renaming the shouldShowAiTutor option flag for clarity and removing an unused aiTutorContextHelper prop from Codebridge plumbing.
Changes:
- Add Python Lab AI Tutor prompt settings editor + persistence/validation, and use those settings to control tutor visibility and system prompt generation.
- Introduce Python Lab prompt-building infrastructure (answer types, triggers/contracts markdown, prompt generator) and Python Lab structured-response schema formatting.
- Rename
shouldShowAiTutoroptiontutorLevel→isTutorLevelacross call sites/tests and split Web Lab 2’s levelbuilder entrypoint for prompt settings.
Reviewed changes
Copilot reviewed 56 out of 56 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| dashboard/config/levels/custom/pythonlab/Allthethings Python Lab 1.level | Publishes/updates a Python Lab level to include ai_tutor_prompt_settings and related properties. |
| dashboard/app/views/levels/editors/fields/_weblab2_ai_tutor_prompt_settings.html.haml | Web Lab 2 levelbuilder field for editing AI Tutor prompt settings via a dedicated webpack entry. |
| dashboard/app/views/levels/editors/fields/_pythonlab_ai_tutor_prompt_settings.html.haml | New Python Lab levelbuilder field for editing AI Tutor prompt settings. |
| dashboard/app/views/levels/editors/_weblab2.html.haml | Switch Web Lab 2 editor to render the new Web Lab 2 prompt settings partial. |
| dashboard/app/views/levels/editors/_pythonlab.html.haml | Switch Python Lab editor to render the new Python Lab prompt settings partial (replacing the old checkbox-only partial). |
| dashboard/app/models/levels/pythonlab.rb | Persist/validate ai_tutor_prompt_settings on Python Lab levels. |
| apps/webpackEntryPoints.js | Add new levelbuilder entrypoints for Web Lab 2 + Python Lab prompt settings; remove the old shared entry. |
| apps/test/unit/lab2/levelEditors/aiTutorPromptSettings/EditAiTutorPromptSettingsTest.tsx | Update unit tests to pass newly-required props to the shared prompt settings editor component. |
| apps/test/unit/aichat/helpers/aiChatAccessTest.ts | Update tests for renamed shouldShowAiTutor parameter (isTutorLevel). |
| apps/src/weblab2/Weblab2View.tsx | Stop passing the removed aiTutorContextHelper prop into Codebridge. |
| apps/src/weblab2/helpers/aiTutorStructuredResponseHelper.ts | Document that accept/reject formatting includes buildJSON. |
| apps/src/templates/instructions/InstructionsWithWorkspace.jsx | Update shouldShowAiTutor call to use isTutorLevel. |
| apps/src/sites/studio/pages/levels/editors/fields/_weblab2_ai_tutor_prompt_settings.js | New Web Lab 2 levelbuilder entrypoint for prompt settings editor with explicit contracts/labels/defaults. |
| apps/src/sites/studio/pages/levels/editors/fields/_pythonlab_ai_tutor_prompt_settings.js | New Python Lab levelbuilder entrypoint for prompt settings editor with Python Lab answer types and instructions. |
| apps/src/sites/studio/pages/levels/editors/fields/_ai_tutor_prompt_settings.js | Remove the old shared levelbuilder entrypoint. |
| apps/src/pythonlab/types.ts | Add Python Lab AI Tutor answer type constants/types. |
| apps/src/pythonlab/PythonlabView.tsx | Use prompt settings to determine tutor visibility and generate the system prompt + response schema settings. |
| apps/src/pythonlab/prompts/promptMaps.ts | Map Python Lab answer types to trigger/contract markdown. |
| apps/src/pythonlab/prompts/environment.md | Add Python Lab environment context for the system prompt. |
| apps/src/pythonlab/prompts/basePrompt.md | Add Python Lab base tutor role/policy prompt. |
| apps/src/pythonlab/prompts/answerTypeTriggers/ask.md | Add trigger text for ask. |
| apps/src/pythonlab/prompts/answerTypeTriggers/buildCSV.md | Add trigger text for buildCSV. |
| apps/src/pythonlab/prompts/answerTypeTriggers/buildJSON.md | Add trigger text for buildJSON. |
| apps/src/pythonlab/prompts/answerTypeTriggers/buildPython.md | Add trigger text for buildPython. |
| apps/src/pythonlab/prompts/answerTypeTriggers/debug.md | Add trigger text for debug. |
| apps/src/pythonlab/prompts/answerTypeTriggers/documentation.md | Add trigger text for documentation. |
| apps/src/pythonlab/prompts/answerTypeTriggers/example.md | Add trigger text for example. |
| apps/src/pythonlab/prompts/answerTypeTriggers/explainCode.md | Add trigger text for explainCode. |
| apps/src/pythonlab/prompts/answerTypeTriggers/hint.md | Add trigger text for hint. |
| apps/src/pythonlab/prompts/answerTypeTriggers/pseudocode.md | Add trigger text for pseudocode. |
| apps/src/pythonlab/prompts/answerTypeTriggers/refusal.md | Add trigger text for refusal. |
| apps/src/pythonlab/prompts/answerTypeTriggers/refusalPythonSnippets.md | Add trigger text for refusalPythonSnippets. |
| apps/src/pythonlab/prompts/answerTypeTriggers/testCase.md | Add trigger text for testCase. |
| apps/src/pythonlab/prompts/answerTypeContracts/ask.md | Add contract text for ask. |
| apps/src/pythonlab/prompts/answerTypeContracts/buildCSV.md | Add contract text for buildCSV. |
| apps/src/pythonlab/prompts/answerTypeContracts/buildJSON.md | Add contract text for buildJSON. |
| apps/src/pythonlab/prompts/answerTypeContracts/buildPython.md | Add contract text for buildPython. |
| apps/src/pythonlab/prompts/answerTypeContracts/debug.md | Add contract text for debug. |
| apps/src/pythonlab/prompts/answerTypeContracts/documentation.md | Add contract text for documentation. |
| apps/src/pythonlab/prompts/answerTypeContracts/example.md | Add contract text for example. |
| apps/src/pythonlab/prompts/answerTypeContracts/explainCode.md | Add contract text for explainCode. |
| apps/src/pythonlab/prompts/answerTypeContracts/hint.md | Add contract text for hint. |
| apps/src/pythonlab/prompts/answerTypeContracts/pseudocode.md | Add contract text for pseudocode. |
| apps/src/pythonlab/prompts/answerTypeContracts/refusal.md | Add contract text for refusal. |
| apps/src/pythonlab/prompts/answerTypeContracts/refusalPythonSnippets.md | Add contract text for refusalPythonSnippets. |
| apps/src/pythonlab/prompts/answerTypeContracts/testCase.md | Add contract text for testCase. |
| apps/src/pythonlab/hooks/useAiTutorResponseSchemaSettings.ts | Add Python Lab hook to provide JSON schema + response formatting callback. |
| apps/src/pythonlab/helpers/aiTutorStructuredResponseHelper.ts | Add Python Lab structured-output schema and formatting helpers (copy/paste flow). |
| apps/src/pythonlab/helpers/aiTutorPromptGenerator.ts | Add Python Lab system prompt generator from selected answer types + customizations. |
| apps/src/pythonlab/helpers/aiTutorContextHelper.ts | Improve Python Lab tutor context: file paths, exclude md, truncate large data files, etc. |
| apps/src/lab2/views/components/Instructions/ResourcePanel/index.tsx | Consider prompt settings answerTypes when deciding whether to show AI Tutor tab in Resource Panel. |
| apps/src/lab2/levelEditors/aiTutorPromptSettings/EditAiTutorPromptSettings.tsx | Refactor shared prompt settings editor to accept lab-provided answer-type config (labels/contracts/defaults). |
| apps/src/codebridge/codebridgeContext/codebridgeContext.tsx | Remove aiTutorContextHelper from Codebridge context type. |
| apps/src/codebridge/Codebridge.tsx | Remove aiTutorContextHelper prop and stop passing it through context. |
| apps/src/aiTutor/views/legacyLabs/AiTutorContainer.tsx | Update shouldShowAiTutor call to use isTutorLevel. |
| apps/src/aichat/helpers/aiChatAccess.ts | Rename shouldShowAiTutor option tutorLevel → isTutorLevel. |
Comments suppressed due to low confidence (1)
dashboard/app/views/levels/editors/fields/_weblab2_ai_tutor_prompt_settings.html.haml:9
@level.properties["ai_tutor_prompt_settings"].to_json || "{}"will return the string "null" when the property is nil (sincenil.to_jsonis truthy), so the fallback never applies. Prefer serializing an empty object when the setting is missing so the client consistently receives{}.
Comment on lines
+8
to
+9
| %script{src: webpack_asset_path('js/levels/editors/fields/_pythonlab_ai_tutor_prompt_settings.js'), | ||
| data: {promptsettings: @level.properties["ai_tutor_prompt_settings"].to_json || "{}"}} |
Comment on lines
+18
to
+24
| responseCallback: (response: string) => { | ||
| const jsonResponse = JSON.parse(response); | ||
| console.log('🤖: AI Tutor response (in jsonSchema callback):', { | ||
| jsonResponse, | ||
| }); | ||
| return formatCopyPasteResponse(jsonResponse.answer); | ||
| }, |
Comment on lines
+226
to
+236
| const systemPrompt = useMemo(() => { | ||
| const answerTypes: AiTutorAnswerType[] = | ||
| (levelProperties.aiTutorPromptSettings | ||
| ?.answerTypes as AiTutorAnswerType[]) || DEFAULT_ANSWER_TYPES; | ||
| return generateAiTutorPrompt( | ||
| answerTypes, | ||
| levelProperties.aiTutorPromptSettings?.answerTypeCustomizations as | ||
| | Partial<Record<AiTutorAnswerType, string>> | ||
| | undefined | ||
| ); | ||
| }, [levelProperties.aiTutorPromptSettings]); |
Comment on lines
+131
to
+137
| private def validate_ai_tutor_prompt_settings | ||
| return if ai_tutor_prompt_settings.nil? | ||
| answer_types = ai_tutor_prompt_settings['answerTypes'] | ||
| unless answer_types.is_a?(Array) && answer_types.all?(String) | ||
| errors.add(:ai_tutor_prompt_settings, 'answerTypes must be an array of strings.') | ||
| end | ||
| end |
Comment on lines
+93
to
+97
| export const generateAiTutorPrompt = ( | ||
| answerTypes: AiTutorAnswerType[], | ||
| answerTypeCustomizations?: Partial<Record<AiTutorAnswerType, string>> | ||
| ): string => { | ||
| const parsedAnswerTypes = generateFinalAnswerTypeList(answerTypes); |
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.
This PR updates AI Tutor in Python Lab:
Links
Jira:
Testing story
Deployment notes
Privacy and security