From f72d4ddc40e122e76798973ad82fe594fc490ce5 Mon Sep 17 00:00:00 2001 From: Kamran Ahmed Date: Fri, 14 Mar 2025 02:04:13 +0000 Subject: [PATCH] Add course regeneration --- .../GenerateCourse/AICourseContent.tsx | 2 +- .../GenerateCourse/GenerateAICourse.tsx | 13 +++- src/components/GenerateCourse/GetAICourse.tsx | 3 +- .../GenerateCourse/ModifyCoursePrompt.tsx | 69 +++++++++++++++++++ .../GenerateCourse/RegenerateOutline.tsx | 27 +++++++- src/helper/generate-ai-course.ts | 7 ++ 6 files changed, 114 insertions(+), 7 deletions(-) create mode 100644 src/components/GenerateCourse/ModifyCoursePrompt.tsx diff --git a/src/components/GenerateCourse/AICourseContent.tsx b/src/components/GenerateCourse/AICourseContent.tsx index 7e30708e7..90eb00f8b 100644 --- a/src/components/GenerateCourse/AICourseContent.tsx +++ b/src/components/GenerateCourse/AICourseContent.tsx @@ -27,7 +27,7 @@ type AICourseContentProps = { course: AiCourse; isLoading: boolean; error?: string; - onRegenerateOutline: () => void; + onRegenerateOutline: (prompt?: string) => void; }; export function AICourseContent(props: AICourseContentProps) { diff --git a/src/components/GenerateCourse/GenerateAICourse.tsx b/src/components/GenerateCourse/GenerateAICourse.tsx index 7041bd0bf..7a054a3cb 100644 --- a/src/components/GenerateCourse/GenerateAICourse.tsx +++ b/src/components/GenerateCourse/GenerateAICourse.tsx @@ -43,8 +43,9 @@ export function GenerateAICourse(props: GenerateAICourseProps) { term: string; difficulty: string; isForce?: boolean; + prompt?: string; }) => { - const { term, difficulty, isForce } = options; + const { term, difficulty, isForce, prompt } = options; if (!isLoggedIn()) { window.location.href = '/ai-tutor'; @@ -61,6 +62,7 @@ export function GenerateAICourse(props: GenerateAICourseProps) { onLoadingChange: setIsLoading, onError: setError, isForce, + prompt, }); }; @@ -95,8 +97,13 @@ export function GenerateAICourse(props: GenerateAICourseProps) { course={course} isLoading={isLoading} error={error} - onRegenerateOutline={() => { - handleGenerateCourse({ term, difficulty, isForce: true }); + onRegenerateOutline={(prompt) => { + handleGenerateCourse({ + term, + difficulty, + isForce: true, + prompt, + }); }} /> ); diff --git a/src/components/GenerateCourse/GetAICourse.tsx b/src/components/GenerateCourse/GetAICourse.tsx index 3219b4eea..b3970d3fd 100644 --- a/src/components/GenerateCourse/GetAICourse.tsx +++ b/src/components/GenerateCourse/GetAICourse.tsx @@ -58,7 +58,7 @@ export function GetAICourse(props: GetAICourseProps) { setError(queryError.message); }, [queryError]); - const handleRegenerateCourse = async () => { + const handleRegenerateCourse = async (prompt?: string) => { if (!aiCourse) { return; } @@ -67,6 +67,7 @@ export function GetAICourse(props: GetAICourseProps) { term: aiCourse.keyword, difficulty: aiCourse.difficulty, slug: courseSlug, + prompt, onCourseChange: (course, rawData) => { queryClient.setQueryData( getAiCourseOptions({ aiCourseSlug: courseSlug }).queryKey, diff --git a/src/components/GenerateCourse/ModifyCoursePrompt.tsx b/src/components/GenerateCourse/ModifyCoursePrompt.tsx new file mode 100644 index 000000000..35583635d --- /dev/null +++ b/src/components/GenerateCourse/ModifyCoursePrompt.tsx @@ -0,0 +1,69 @@ +import { useState } from 'react'; +import { Modal } from '../Modal'; + +export type ModifyCoursePromptProps = { + onClose: () => void; + onSubmit: (prompt: string) => void; +}; + +export function ModifyCoursePrompt(props: ModifyCoursePromptProps) { + const { onClose, onSubmit } = props; + + const [prompt, setPrompt] = useState(''); + + const handleSubmit = (e: React.FormEvent) => { + e.preventDefault(); + onSubmit(prompt); + }; + + return ( + +
+
+

+ Give AI more context +

+

+ Pass additional information to the AI to generate a course outline. +

+
+
+