Skip to content

LLM Frontend #2554

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

Closed
wants to merge 28 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
b8ef27b
LLM Frontend
clementlemon02 Jul 16, 2023
967135d
Merge branch 'master' of https://github.com/source-academy/frontend i…
RichDom2185 Jul 18, 2023
d68f0a9
Use optional chaining and reformat files
RichDom2185 Jul 18, 2023
3f07e69
Run yarn format
RichDom2185 Jul 18, 2023
956a6d0
Merge branch 'master' into master
RichDom2185 Jul 26, 2023
d3e6e39
Merge branch 'master' into master
RichDom2185 Jul 29, 2023
443b232
Merge branch 'master' into master
RichDom2185 Jul 30, 2023
00f2cc6
Merge branch 'master' into master
RichDom2185 Aug 6, 2023
802cc65
Merge branch 'master' into master
RichDom2185 Aug 7, 2023
c694de1
fix lint issues
clementlemon02 Aug 8, 2023
b4b837d
Merge branch 'master' of https://github.com/clementlemon02/SA_frontend
clementlemon02 Aug 8, 2023
bf271ce
Merge branch 'master' into master
clementlemon02 Aug 8, 2023
8887a69
fix lint issues
clementlemon02 Aug 8, 2023
2e0f1f3
fix lint issues
clementlemon02 Aug 8, 2023
1738c6c
Merge branch 'master' of https://github.com/clementlemon02/SA_frontend
clementlemon02 Aug 8, 2023
49c5da7
fix lint issues
clementlemon02 Aug 8, 2023
c3dfea0
fix lint issues
clementlemon02 Aug 8, 2023
00149d2
fix lint issues
clementlemon02 Aug 9, 2023
f169755
Merge branch 'master' into master
RichDom2185 Aug 10, 2023
9a9fc68
Remove unnecessary empty line
RichDom2185 Aug 10, 2023
fe5728b
resolving comments
clementlemon02 Aug 12, 2023
5ab2851
Merge branch 'master' of https://github.com/clementlemon02/SA_frontend
clementlemon02 Aug 12, 2023
3ef944c
Merge branch 'master' into master
clementlemon02 Aug 12, 2023
197994f
fix format
clementlemon02 Aug 12, 2023
a45cdce
Merge branch 'master' of https://github.com/clementlemon02/SA_frontend
clementlemon02 Aug 12, 2023
63324f4
Merge branch 'master' into master
RichDom2185 Aug 17, 2023
8648f59
Merge branch 'master' into master
RichDom2185 Aug 21, 2023
6e2d8c5
Merge branch 'master' into master
RichDom2185 Aug 22, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/commons/application/actions/__tests__/SessionActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ test('setCourseConfiguration generates correct action object', () => {
sourceChapter: Chapter.SOURCE_1,
sourceVariant: Variant.DEFAULT,
moduleHelpText: 'Help text',
defaultLlmPrompt: 'defaul Llm Prompt',
assessmentTypes: ['Missions', 'Quests', 'Paths', 'Contests', 'Others']
};
const action = setCourseConfiguration(courseConfig);
Expand Down Expand Up @@ -510,6 +511,7 @@ test('updateGradingOverviews generates correct action object', () => {
{
assessmentId: 1,
assessmentName: 'test assessment',
questions: '',
assessmentType: 'Contests',
initialXp: 0,
xpBonus: 100,
Expand Down Expand Up @@ -612,6 +614,7 @@ test('updateCourseConfig generates correct action object', () => {
sourceChapter: Chapter.SOURCE_1,
sourceVariant: Variant.DEFAULT,
moduleHelpText: 'Help text',
defaultLlmPrompt: 'default LLM Prompt',
assessmentTypes: ['Missions', 'Quests', 'Paths', 'Contests', 'Others']
};
const action = updateCourseConfig(courseConfig);
Expand Down
3 changes: 3 additions & 0 deletions src/commons/application/reducers/__tests__/SessionReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ test('SET_COURSE_CONFIGURATION works correctly', () => {
sourceChapter: Chapter.SOURCE_1,
sourceVariant: Variant.DEFAULT,
moduleHelpText: 'Help text',
defaultLlmPrompt: 'default LLM Prompt',
assessmentTypes: ['Missions', 'Quests', 'Paths', 'Contests', 'Others']
};
const action = {
Expand Down Expand Up @@ -474,6 +475,7 @@ const gradingOverviewTest1: GradingOverview[] = [
{
assessmentId: 1,
assessmentName: 'test assessment',
questions: '',
assessmentType: 'Contests',
initialXp: 0,
xpBonus: 100,
Expand All @@ -495,6 +497,7 @@ const gradingOverviewTest2: GradingOverview[] = [
{
assessmentId: 2,
assessmentName: 'another assessment',
questions: '',
assessmentType: 'Quests',
initialXp: 20,
xpBonus: 250,
Expand Down
3 changes: 3 additions & 0 deletions src/commons/application/types/SessionTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export const UPDATE_TOTAL_XP = 'UPDATE_TOTAL_XP';
export const UPDATE_ALL_USER_XP = 'UPDATE_ALL_USER_XP';
export const UPDATE_ASSESSMENT = 'UPDATE_ASSESSMENT';
export const UPDATE_GRADING_OVERVIEWS = 'UPDATE_GRADING_OVERVIEWS';
export const UPDATE_GRADING_OVERVIEWS_TEST = 'UPDATE_GRADING_OVERVIEWS_TEST';
export const UPDATE_GRADING = 'UPDATE_GRADING';
export const FETCH_NOTIFICATIONS = 'FETCH_NOTIFICATIONS';
export const ACKNOWLEDGE_NOTIFICATIONS = 'ACKNOWLEDGE_NOTIFICATIONS';
Expand Down Expand Up @@ -106,6 +107,7 @@ export type SessionState = {
readonly sourceChapter?: number;
readonly sourceVariant?: Variant;
readonly moduleHelpText?: string;
readonly defaultLlmPrompt?: string;
readonly assetsPrefix?: string;

readonly assessmentConfigurations?: AssessmentConfiguration[];
Expand Down Expand Up @@ -171,6 +173,7 @@ export type CourseConfiguration = {
sourceChapter: Chapter;
sourceVariant: Variant;
moduleHelpText: string;
defaultLlmPrompt: string;
assetsPrefix: string;
};

Expand Down
37 changes: 36 additions & 1 deletion src/commons/dropdown/DropdownCreateCourse.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ const DropdownCreateCourse: React.FC<DialogProps> = props => {
enableSourcecast: true,
sourceChapter: Chapter.SOURCE_1,
sourceVariant: Variant.DEFAULT,
moduleHelpText: ''
moduleHelpText: '',
defaultLlmPrompt: ''
});

const [courseHelpTextSelectedTab, setCourseHelpTextSelectedTab] =
Expand Down Expand Up @@ -173,6 +174,40 @@ const DropdownCreateCourse: React.FC<DialogProps> = props => {
)}
</FormGroup>

<FormGroup helperText="defaultLlmPrompt" labelFor="defaultLlmPrompt">
<Text tagName="span">Default LLM Prompt&nbsp;</Text>
<Text tagName="span" className="optional-text">
(optional)
</Text>
<Tabs
selectedTabId={courseHelpTextSelectedTab}
onChange={onChangeTabs}
className="module-help-text-tabs"
>
<Tab id={CourseHelpTextEditorTab.WRITE} title="Write" />
<Tab id={CourseHelpTextEditorTab.PREVIEW} title="Preview" />
</Tabs>
{courseHelpTextSelectedTab === CourseHelpTextEditorTab.WRITE && (
<TextArea
id="defaultLlmPrompt"
className="input-textarea"
fill={true}
value={courseConfig.defaultLlmPrompt}
onChange={e =>
setCourseConfig({
...courseConfig,
defaultLlmPrompt: e.target.value
})
}
/>
)}
{courseHelpTextSelectedTab === CourseHelpTextEditorTab.PREVIEW && (
<div className="input-markdown">
<Markdown content={courseConfig.defaultLlmPrompt || ''} openLinksInNewWindow />
</div>
)}
</FormGroup>

<div className="boolean-container">
<div>
<Switch
Expand Down
46 changes: 46 additions & 0 deletions src/commons/dropdown/DropdownPrompt.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { Classes, Dialog } from '@blueprintjs/core';
import { IconNames } from '@blueprintjs/icons';
import * as React from 'react';

import Markdown from '../Markdown';
import { Links } from '../utils/Constants';
import { useTypedSelector } from '../utils/Hooks';

type DialogProps = {
isOpen: boolean;
onClose: () => void;
};

const DropdownPrompt: React.FC<DialogProps> = props => {
const defaultLlmPrompt = useTypedSelector(store => store.session.defaultLlmPrompt);

return (
<Dialog
className="help"
icon={IconNames.ERROR}
isCloseButtonShown={true}
isOpen={props.isOpen}
onClose={props.onClose}
title="Help"
>
<div className={Classes.DIALOG_BODY}>
{defaultLlmPrompt ? (
<Markdown content={defaultLlmPrompt} openLinksInNewWindow />
) : (
<>
<p>
We recommend recent updates of the browsers <b>Google Chrome</b>,{' '}
<b>Microsoft Edge</b>, or <b>Mozilla Firefox</b> to visit the Source Academy.
</p>
<p>
If you encounter issues with the Source Academy using these browsers, please use the
issue system of the{' '}
<a href={Links.githubIssues}>Source Academy frontend repository on GitHub</a>.
</p>
</>
)}
</div>
</Dialog>
);
};
export default DropdownPrompt;
3 changes: 3 additions & 0 deletions src/commons/mocks/GradingMocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const mockGradingOverviews: GradingOverview[] = [
assessmentType: 'Missions',
assessmentId: 0,
assessmentName: 'Mission 0 ',
questions: '',
currentXp: 69,
xpBonus: 10,
initialXp: 69,
Expand All @@ -29,6 +30,7 @@ export const mockGradingOverviews: GradingOverview[] = [
assessmentType: 'Missions',
assessmentId: 1,
assessmentName: 'Mission 1',
questions: '',
currentXp: -2,
xpBonus: 12,
initialXp: 0,
Expand All @@ -47,6 +49,7 @@ export const mockGradingOverviews: GradingOverview[] = [
assessmentType: 'Missions',
assessmentId: 0,
assessmentName: 'Mission 0',
questions: '',
currentXp: 1000,
xpBonus: 12,
initialXp: 996,
Expand Down
2 changes: 2 additions & 0 deletions src/commons/mocks/UserMocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ export const mockCourseConfigurations: CourseConfiguration[] = [
sourceChapter: Chapter.SOURCE_1,
sourceVariant: Variant.DEFAULT,
moduleHelpText: '',
defaultLlmPrompt: '',
assetsPrefix: ''
},
{
Expand All @@ -145,6 +146,7 @@ export const mockCourseConfigurations: CourseConfiguration[] = [
sourceChapter: Chapter.SOURCE_2,
sourceVariant: Variant.DEFAULT,
moduleHelpText: 'Help Text!',
defaultLlmPrompt: 'Default LLM Prompt',
assetsPrefix: ''
}
];
Expand Down
1 change: 1 addition & 0 deletions src/commons/sagas/RequestsSaga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,7 @@ export const getGradingOverviews = async (
assessmentType: overview.assessment.type,
studentId: overview.student.id,
studentName: overview.student.name,
questions: overview.questions,
submissionId: overview.id,
submissionStatus: overview.status,
groupName: overview.student.groupName,
Expand Down
6 changes: 5 additions & 1 deletion src/commons/sagas/__tests__/BackendSaga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ const mockCourseConfiguration1: CourseConfiguration = {
sourceChapter: Chapter.SOURCE_1,
sourceVariant: Variant.DEFAULT,
moduleHelpText: 'Help text',
defaultLlmPrompt: 'default LLM prompt',
assetsPrefix: ''
};

Expand Down Expand Up @@ -206,6 +207,7 @@ const mockCourseConfiguration2: CourseConfiguration = {
sourceChapter: Chapter.SOURCE_4,
sourceVariant: Variant.DEFAULT,
moduleHelpText: 'Help text',
defaultLlmPrompt: 'default LLM prompt',
assetsPrefix: ''
};

Expand Down Expand Up @@ -889,6 +891,7 @@ describe('Test UPDATE_COURSE_CONFIG action', () => {
sourceChapter: Chapter.SOURCE_4,
sourceVariant: Variant.DEFAULT,
moduleHelpText: 'Help',
defaultLlmPrompt: 'default LLM prompt',
assetsPrefix: ''
};

Expand Down Expand Up @@ -985,7 +988,8 @@ describe('Test CREATE_COURSE action', () => {
enableSourcecast: true,
sourceChapter: Chapter.SOURCE_1,
sourceVariant: Variant.DEFAULT,
moduleHelpText: 'Help Text'
moduleHelpText: 'Help Text',
defaultLlmPrompt: 'default Llm prompt'
};
const user = mockUser;
const courseConfiguration = mockCourseConfiguration1;
Expand Down
3 changes: 2 additions & 1 deletion src/features/academy/__tests__/AcademyActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ test('createCourse generates correct action object', () => {
enableSourcecast: true,
sourceChapter: Chapter.SOURCE_1,
sourceVariant: Variant.DEFAULT,
moduleHelpText: 'Help Text'
moduleHelpText: 'Help Text',
defaultLlmPrompt: 'default LLM prompt'
};

const action = createCourse(courseConfig);
Expand Down
1 change: 1 addition & 0 deletions src/features/grading/GradingTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export type GradingOverview = {
studentName: string;
submissionId: number;
submissionStatus: string;
questions: string;
groupName: string;
groupLeaderId?: number;
gradingStatus: GradingStatus;
Expand Down
1 change: 1 addition & 0 deletions src/pages/__tests__/localStorage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const mockShortDefaultState: SavedState = {
enableAchievements: defaultState.session.enableAchievements,
enableSourcecast: defaultState.session.enableSourcecast,
moduleHelpText: defaultState.session.moduleHelpText,
defaultLlmPrompt: defaultState.session.defaultLlmPrompt,
assetsPrefix: defaultState.session.assetsPrefix,
assessmentConfigurations: defaultState.session.assessmentConfigurations
},
Expand Down
6 changes: 4 additions & 2 deletions src/pages/academy/adminPanel/AdminPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ const AdminPanel: React.FC = () => {
enableGame: true,
enableAchievements: true,
enableSourcecast: true,
moduleHelpText: ''
moduleHelpText: '',
defaultLlmPrompt: ''
});

const dispatch = useDispatch();
Expand Down Expand Up @@ -84,7 +85,8 @@ const AdminPanel: React.FC = () => {
enableGame: session.enableGame,
enableAchievements: session.enableAchievements,
enableSourcecast: session.enableSourcecast,
moduleHelpText: session.moduleHelpText
moduleHelpText: session.moduleHelpText,
defaultLlmPrompt: session.defaultLlmPrompt
});

// IMPT: To prevent mutation of props
Expand Down
Loading