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-441: Finish UI refactor #57889
Conversation
}; | ||
thunkAPI.dispatch(addChatMessage(newMessage)); | ||
} | ||
const newMessage: ChatCompletionMessage = { |
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.
Now, every scenario (general chat/compilation/validation) adds its "question" (the inputted question/"Why doesn't my code compile?"/"Why aren't my tests passing?") to state.
studentInput: string; | ||
tutorType: AITutorTypesValue | undefined; | ||
studentCode: string; |
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.
Added the student code to the ChatContext
because I'll now need to include it in the formattedQuestion along with the studentInput
, since I'm not using three different system prompts anymore.
import {useAppSelector} from '@cdo/apps/util/reduxHooks'; | ||
import Message from './Message'; | ||
|
||
const AITutorChatWorkspace: React.FunctionComponent = () => { |
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.
None of the existing logic in this component changed. I just removed unused logic and unnecessary divs/styling. I renamed these files and restructured them so that the organization of AITutorContainer
, AITutorChatWorkspace
, and AITutorFooter
matches the structure of RubricContainer
, RubricContent
, and RubricSubmitFooter
(the AI TA components). This allowed me to snag their most recent styling :)
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.
Just in case anyone is curious: https://github.com/code-dot-org/code-dot-org/blob/staging/apps/src/templates/rubrics/RubricContainer.jsx
@@ -0,0 +1,79 @@ | |||
import classnames from 'classnames'; |
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 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.
This component changed significantly to accommodate the new organization/UI. I also made it draggable because it was helpful for testing. I've pasted the diff between this and the old equivalent, which was aiTutorPanel
: https://github.com/code-dot-org/code-dot-org/blob/staging/apps/src/code-studio/components/aiTutor/aiTutorPanel.tsx
@@ -39,7 +39,7 @@ const AITutorFloatingActionButton: React.FunctionComponent = () => { | |||
type="button" | |||
/> | |||
<Provider store={store}> | |||
<AITutorPanel open={isOpen} /> | |||
<AITutorContainer open={isOpen} closeTutor={handleClick} /> |
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.
Passing this handler enables a close with an "X" in the upper right-hand corner.
state => state.aiTutor.isWaitingForChatResponse | ||
); | ||
|
||
const level = useAppSelector(state => state.aiTutor.level); |
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.
Most of this logic isn't new, and is borrowed from a previous component called userChatMessageEditor
: https://github.com/code-dot-org/code-dot-org/blob/staging/apps/src/code-studio/components/aiTutor/userChatMessageEditor.tsx
@@ -76,6 +79,9 @@ const ChatMessage: React.FunctionComponent<ChatMessageProps> = ({message}) => { | |||
|
|||
{isAssistant(message.role) && ( | |||
<div className={style.assistantMessageContainer}> | |||
<Typography semanticTag="h5" visualAppearance="heading-xs"> | |||
AI Tutor ({message.role}) |
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.
@import 'font'; | ||
@import '@cdo/apps/componentLibrary/common/styles/mixins'; | ||
|
||
.aiTutorContainer { |
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.
Most of these CSS changes add the updated AI TA-like UI. I duplicated everything to guarantee we wouldn't break anything with AI TA.
import {StudentAccessData} from '@cdo/apps/aiTutor/types'; | ||
|
||
/** | ||
* Renders toggles to control student access to AI Tutor. | ||
*/ | ||
|
||
interface AITutorTeacherControlsProps { | ||
interface AccessControlsProps { |
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.
I initially started renaming things because I was having trouble with git not detecting case-only changes in filenames when I moved from camelCase to PascalCase on these components (I had to modify my git config and using git mv
to get it to pick all of them up). But I left the simpler names in place. Now that these are all scoped to the src/aiTutor
directory, it doesn't feel like they all need to be prepended with AITutor
.
@@ -1,4 +1,3 @@ | |||
export const CHAT_COMPLETION_URL = '/openai/chat_completion'; |
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.
This endpoint is only used in the chatApi.ts
file that aichat folks say they don't want in their directory anymore.
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.
Everything now lives in apps/src/aiTutor
. Navigating back and forth between apps/src/aiTutor
and apps/src/code-studio/components/aiTutor
was tough, especially when apps/src/aichat
is very similar to apps/src/aiTutor
and I was often accidentally opening the wrong copy of a file.
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.
Copied from apps/src/code-studio/components/aiTutor/chat-workspace.module.scss
.
@@ -10,7 +10,7 @@ import { | |||
AI_CUSTOMIZATIONS_LABELS, | |||
} from '../views/modelCustomization/constants'; | |||
import {initialChatMessages} from '../constants'; | |||
import {getChatCompletionMessage} from '../chatApi'; | |||
import {getChatCompletionMessage} from '../../aiTutor/chatApi'; |
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.
Hey Emily - will you be calling on getChatCompletionMessage
from this file? I see you have it in aiTutorRedux.ts
. FWIW - I'm currently working on a PR that is updating this line.
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, Alice! No, AI Tutor doesn't need this. Your PR will be good to update it after this one.
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.
These changes seem reasonable to me!
changes within |
This completes a refactor of the AI Tutor code that @Erin007 and @kakiha11 started.
Forgive me for the massive diff 🙈 I have tried to leave comments and screenshots of manually generated diffs where possible. Please feel free to leave specific feedback on things you feel could have been separated out despite the nature of the refactor and ask as many clarifying questions as needed!
In the following PR:
apps/src/aiTutor
from being split between that folder andapps/src/code-studio/components
aichat
directory has been copied into theaiTutor
directory, so the folks working on generative AI are free to do withaichat
what they wishOld UI:
New UI:
Links
Jira ticket: https://codedotorg.atlassian.net/browse/CT-441
Testing story
Since no one is using this until the closed beta, I tested that most things work manually.
This included each of the three buttons (submit, "Why doesn't my code compile?", "Why aren't my tests passing?") posting correctly to Open AI, receiving responses, and persisting the chat history to the database. I also tested that scrolling still works and that the view is appropriately locked down when the tutor is disabled.
I tested some of these things before I got the CSS on the buttons on the bottom correct, so ignore any wonky CSS in the footer (the image above is the source of truth for the footer UI).
Compilation working:
Validation working:
Scrolling still working:
Locked out view:
Deployment strategy
Follow-up work
Privacy
Security
Caching
PR Checklist: