-
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] CT-253: Teachers can view flagged chats #57669
Changes from 10 commits
aa332c1
9528eae
8a51b60
dcf308a
45cd8f9
2b3f1e0
f1286fb
424ecf5
cd3ca98
bde8c88
15c5893
9b3f650
3f1a094
dd20f0f
67fd49d
2708594
56979a7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,18 +7,20 @@ import { | |
} from '@cdo/apps/aiTutor/constants'; | ||
import {savePromptAndResponse} from '../interactionsApi'; | ||
import { | ||
TutorType, | ||
Role, | ||
Status, | ||
AITutorInteractionStatus as Status, | ||
ChatCompletionMessage, | ||
Level, | ||
ChatContext, | ||
AITutorTypesValue, | ||
AITutorTypes as TutorTypes, | ||
AITutorInteractionStatusValue, | ||
} from '../types'; | ||
|
||
const registerReducers = require('@cdo/apps/redux').registerReducers; | ||
|
||
export interface AITutorState { | ||
selectedTutorType: TutorType | undefined; | ||
selectedTutorType: AITutorTypesValue | undefined; | ||
level: Level | undefined; | ||
scriptId: number | undefined; | ||
aiResponse: string | undefined; | ||
|
@@ -58,9 +60,9 @@ export const askAITutor = createAsyncThunk( | |
}; | ||
|
||
const tutorType = chatContext.tutorType; | ||
const generalChat = tutorType === TutorType.GENERAL_CHAT; | ||
const compilation = tutorType === TutorType.COMPILATION; | ||
const validation = tutorType === TutorType.VALIDATION; | ||
const generalChat = tutorType === TutorTypes.GENERAL_CHAT; | ||
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. I got a little refactor happy and renamed TutorType to TutorTypes to indicate that this references an object that stores all of the types/multiple fields 😅 |
||
const compilation = tutorType === TutorTypes.COMPILATION; | ||
const validation = tutorType === TutorTypes.VALIDATION; | ||
|
||
let systemPrompt; | ||
if (validation) { | ||
|
@@ -129,7 +131,7 @@ const aiTutorSlice = createSlice({ | |
reducers: { | ||
setSelectedTutorType: ( | ||
state, | ||
action: PayloadAction<TutorType | undefined> | ||
action: PayloadAction<AITutorTypesValue | undefined> | ||
) => { | ||
state.selectedTutorType = action.payload; | ||
}, | ||
|
@@ -159,7 +161,7 @@ const aiTutorSlice = createSlice({ | |
}, | ||
updateChatMessageStatus: ( | ||
state, | ||
action: PayloadAction<{id: number; status: Status}> | ||
action: PayloadAction<{id: number; status: AITutorInteractionStatusValue}> | ||
) => { | ||
const {id, status} = action.payload; | ||
const chatMessage = state.chatMessages.find(msg => msg.id === id); | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,61 +1,68 @@ | ||||||
import { | ||||||
AiTutorInteractionSaveStatus, | ||||||
AiTutorTypes, | ||||||
AiTutorInteractionStatus as AITutorInteractionStatus, | ||||||
AiTutorTypes as AITutorTypes, | ||||||
PiiTypes as PII, | ||||||
} from '@cdo/apps/util/sharedConstants'; | ||||||
|
||||||
export type ChatCompletionMessage = { | ||||||
export type AITutorTypesValue = | ||||||
(typeof AITutorTypes)[keyof typeof AITutorTypes]; | ||||||
export type AITutorInteractionStatusValue = | ||||||
(typeof AITutorInteractionStatus)[keyof typeof AITutorInteractionStatus]; | ||||||
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. I was operating at the edge of my TypeScript knowledge, so I'd appreciate a second set of eyes. I'm also tripped up by naming conventions here and would appreciate any guidance. 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. I haven't seen this syntax before, but let's try to figure it out!
If you put those together, we are getting the types for each key in 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. I can't find an easy way to turn the values into a type if that's what we want. 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. The 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. For example -
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. Thank you so much for the deep dive here, Molly and Sanchit! 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. Wrinkle: The imported constant comes from here: code-dot-org/apps/script/generateSharedConstants.rb Lines 40 to 41 in 15c5893
I tried
And that doesn't work. One idea is to modify generateSharedConstants to re-export with const assertion, but that doesn't seem worth the trouble assuming it's possible. 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. Something like this doesn't seem to work either:
I'm wondering if it's just easiest to have...
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. yeah I think just copying the constants over seems fine here |
||||||
|
||||||
export {AITutorInteractionStatus, AITutorTypes, PII}; | ||||||
|
||||||
export interface ChatCompletionMessage { | ||||||
id: number; | ||||||
role: Role; | ||||||
chatMessageText: string; | ||||||
status: Status; | ||||||
status: AITutorInteractionStatusValue; | ||||||
timestamp?: string; | ||||||
}; | ||||||
} | ||||||
|
||||||
export type AITutorInteraction = { | ||||||
export interface AITutorInteraction { | ||||||
userId?: number; | ||||||
levelId?: number; | ||||||
scriptId?: number; | ||||||
type: TutorType | undefined; | ||||||
type: AITutorTypesValue | undefined; | ||||||
isProjectBacked?: boolean; | ||||||
prompt: string; | ||||||
status: string; | ||||||
aiResponse?: string; | ||||||
}; | ||||||
} | ||||||
|
||||||
export type StudentChatRow = { | ||||||
export interface StudentChatRow { | ||||||
aiModelVersion: string; | ||||||
aiResponse?: string; | ||||||
createdAt: string; | ||||||
id: number; | ||||||
studentName: string; | ||||||
type: TutorType; | ||||||
levelId?: number; | ||||||
projectId?: string; | ||||||
prompt: string; | ||||||
scriptId?: number; | ||||||
status: string; | ||||||
aiResponse?: string; | ||||||
createdAt: string; | ||||||
}; | ||||||
studentName: string; | ||||||
type: AITutorTypesValue; | ||||||
updatedAt?: string; | ||||||
userId: number; | ||||||
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. These fields seemed missing but were on the |
||||||
} | ||||||
|
||||||
export type Level = { | ||||||
export interface Level { | ||||||
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. Per recommendation from @molly-moen, prefer |
||||||
id: number; | ||||||
type: string; | ||||||
hasValidation: boolean; | ||||||
isAssessment: boolean; | ||||||
isProjectBacked: boolean; | ||||||
}; | ||||||
} | ||||||
|
||||||
export interface ChatContext { | ||||||
// studentInput is the last user message for general chat | ||||||
// or the student's code for compilation and validaiton. | ||||||
studentInput: string; | ||||||
tutorType: TutorType | undefined; | ||||||
tutorType: AITutorTypesValue | undefined; | ||||||
} | ||||||
|
||||||
export enum Role { | ||||||
ASSISTANT = 'assistant', | ||||||
USER = 'user', | ||||||
SYSTEM = 'system', | ||||||
} | ||||||
export type Status = | ||||||
(typeof AiTutorInteractionSaveStatus)[keyof typeof AiTutorInteractionSaveStatus]; | ||||||
export const Status = AiTutorInteractionSaveStatus; | ||||||
export const PII = [Status.EMAIL, Status.ADDRESS, Status.PHONE]; | ||||||
|
||||||
export type TutorType = (typeof AiTutorTypes)[keyof typeof AiTutorTypes]; | ||||||
export const TutorType = AiTutorTypes; |
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. FWIW I expect that for Gen AI we may just create a new API file since we're no longer using this chat API. If it makes more sense to just move this to the aiTutor directory, feel free! 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. I think you're right that refactoring this code makes sense. It looks like the only way this file is used is to |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,19 @@ | ||
import {LevelProperties} from '@cdo/apps/lab2/types'; | ||
import {AiTutorInteractionSaveStatus} from '@cdo/apps/util/sharedConstants'; | ||
import { | ||
AiTutorInteractionStatus as AITutorInteractionStatus, | ||
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. Slightly out of scope, but should this be called 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. @bencodeorg I think my ultimate goal is in the spirit of this comment, which is to condense/standardize things. I don't know how long the AI Chat use case will continue to be relevant. Per @sanchitmalhotra126's comment above, the best way to achieve clarity/reusability might be to 1) wait until we have a better understanding of the API for the gen AI unit, 2) use it to make these values more reusable across gen AI and AI tutor (and then rename them then if applicable), and 3) ultimately look to deprecate any aichat code that doesn't move to AI Tutor or Gen AI code? As far as I know, the AI Chat allthethings level is no longer used... 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. Are you all creating a new directory or using the aichat directory? 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. We're actively doing development of the gen AI unit using the AI Chat allthethings level! AI Chat is being repurposed as gen AI. The API will probably be replaced though, to Sanchit's point. Fine to leave as-is for now, just a thought :) 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. sorry just saw comment re: directory, using the aichat directory! |
||
PiiTypes as PII, | ||
} from '@cdo/apps/util/sharedConstants'; | ||
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. I don't think this file is used much anymore, but it shares types with AI tutor code. Tagging @sanchitmalhotra126 @bencodeorg @fisher-alice for confirmation this is okay. 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. The new "generative AI" lab is using being built on the aichat lab, so it's back in use! |
||
|
||
export type AITutorInteractionStatusType = | ||
(typeof AITutorInteractionStatus)[keyof typeof AITutorInteractionStatus]; | ||
|
||
export {PII, AITutorInteractionStatus}; | ||
|
||
export type ChatCompletionMessage = { | ||
id: number; | ||
role: Role; | ||
chatMessageText: string; | ||
status: Status; | ||
status: AITutorInteractionStatusType; | ||
timestamp?: string; | ||
}; | ||
|
||
|
@@ -14,12 +22,6 @@ export enum Role { | |
USER = 'user', | ||
SYSTEM = 'system', | ||
} | ||
|
||
export type Status = | ||
(typeof AiTutorInteractionSaveStatus)[keyof typeof AiTutorInteractionSaveStatus]; | ||
export const Status = AiTutorInteractionSaveStatus; | ||
export const PII = [Status.EMAIL, Status.ADDRESS, Status.PHONE]; | ||
|
||
export interface AichatLevelProperties extends LevelProperties { | ||
// --- DEPRECATED - used for old AI Chat | ||
systemPrompt: 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.
See the rationale below for refactoring here. Is it dangerous to refactor shared constants?
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.
Seems ok to me, especially since it's something pretty clearly owned/consumed by your team?
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.
Thinking about Ben's comment at https://github.com/code-dot-org/code-dot-org/pull/57669/files#r1548141051 - are their plans to use
STATUS
on the backend foraichat
@sanchitmalhotra126 ?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 think we could but it's a bit unclear since our API design is still being finalized. I'm okay with keeping this in the AI Tutor space for now and revisiting/refactoring when the API is more solidified.
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.
When I said "dangerous," what I was thinking of was, "Is there some script or something I need to reseed this constant file?" If tests are passing, I'll assume not. I'm happy to refactor this more down the line if it's useful for generative AI.