diff --git a/src/components/GenerateGuide/GenerateAIGuide.tsx b/src/components/GenerateGuide/GenerateAIGuide.tsx index 64ed875a0..c1d512ec3 100644 --- a/src/components/GenerateGuide/GenerateAIGuide.tsx +++ b/src/components/GenerateGuide/GenerateAIGuide.tsx @@ -7,6 +7,8 @@ import { AIGuideContent } from './AIGuideContent'; import { queryClient } from '../../stores/query-client'; import { getAiGuideOptions } from '../../queries/ai-guide'; import { LoadingChip } from '../LoadingChip'; +import type { QuestionAnswerChatMessage } from '../ContentGenerator/QuestionAnswerChat'; +import { getQuestionAnswerChatMessages } from '../../lib/ai-questions'; type GenerateAIGuideProps = { onGuideSlugChange?: (guideSlug: string) => void; @@ -26,48 +28,32 @@ export function GenerateAIGuide(props: GenerateAIGuideProps) { useEffect(() => { const params = getUrlParams(); const paramsTerm = params?.term; - const paramsDepth = params?.depth; const paramsSrc = params?.src || 'search'; - if (!paramsTerm || !paramsDepth) { + if (!paramsTerm) { return; } - let paramsGoal = ''; - let paramsAbout = ''; - let paramsCustomInstructions = ''; - + let questionAndAnswers: QuestionAnswerChatMessage[] = []; const sessionId = params?.id; if (sessionId) { - const fineTuneData = getCourseFineTuneData(sessionId); - if (fineTuneData) { - paramsGoal = fineTuneData.goal; - paramsAbout = fineTuneData.about; - paramsCustomInstructions = fineTuneData.customInstructions; - } + questionAndAnswers = getQuestionAnswerChatMessages(sessionId); } handleGenerateDocument({ term: paramsTerm, - depth: paramsDepth, - instructions: paramsCustomInstructions, - goal: paramsGoal, - about: paramsAbout, src: paramsSrc, + questionAndAnswers, }); }, []); const handleGenerateDocument = async (options: { term: string; - depth: string; - instructions?: string; - goal?: string; - about?: string; isForce?: boolean; prompt?: string; src?: string; + questionAndAnswers?: QuestionAnswerChatMessage[]; }) => { - const { term, depth, isForce, prompt, instructions, goal, about, src } = - options; + const { term, isForce, prompt, src, questionAndAnswers } = options; if (!isLoggedIn()) { window.location.href = '/ai'; @@ -76,7 +62,6 @@ export function GenerateAIGuide(props: GenerateAIGuideProps) { await generateGuide({ term, - depth, onDetailsChange: (details) => { const { guideId, guideSlug, creatorId, title } = details; @@ -86,7 +71,6 @@ export function GenerateAIGuide(props: GenerateAIGuideProps) { title, html: htmlRef.current, keyword: term, - depth, content, tokens: { prompt: 0, @@ -96,6 +80,7 @@ export function GenerateAIGuide(props: GenerateAIGuideProps) { relatedTopics: [], deepDiveTopics: [], questions: [], + questionAndAnswers, viewCount: 0, lastVisitedAt: new Date(), createdAt: new Date(), @@ -112,12 +97,10 @@ export function GenerateAIGuide(props: GenerateAIGuideProps) { }, onLoadingChange: setIsLoading, onError: setError, - instructions, - goal, - about, isForce, prompt, src, + questionAndAnswers, onHtmlChange: (html) => { htmlRef.current = html; setHtml(html); diff --git a/src/helper/generate-ai-guide.ts b/src/helper/generate-ai-guide.ts index fb33f9564..350017424 100644 --- a/src/helper/generate-ai-guide.ts +++ b/src/helper/generate-ai-guide.ts @@ -2,6 +2,7 @@ import { queryClient } from '../stores/query-client'; import { getAiCourseLimitOptions } from '../queries/ai-course'; import { readChatStream } from '../lib/chat'; import { markdownToHtmlWithHighlighting } from '../lib/markdown'; +import type { QuestionAnswerChatMessage } from '../components/ContentGenerator/QuestionAnswerChat'; type GuideDetails = { guideId: string; @@ -12,13 +13,9 @@ type GuideDetails = { type GenerateGuideOptions = { term: string; - depth: string; slug?: string; isForce?: boolean; prompt?: string; - instructions?: string; - goal?: string; - about?: string; onGuideSlugChange?: (guideSlug: string) => void; onGuideChange?: (guide: string) => void; onLoadingChange?: (isLoading: boolean) => void; @@ -28,26 +25,24 @@ type GenerateGuideOptions = { onStreamingChange?: (isStreaming: boolean) => void; onDetailsChange?: (details: GuideDetails) => void; onFinish?: () => void; + questionAndAnswers?: QuestionAnswerChatMessage[]; }; export async function generateGuide(options: GenerateGuideOptions) { const { term, slug, - depth, onGuideChange, onLoadingChange, onError, isForce = false, prompt, - instructions, - goal, - about, src = 'search', onHtmlChange, onStreamingChange, onDetailsChange, onFinish, + questionAndAnswers, } = options; onLoadingChange?.(true); @@ -80,12 +75,9 @@ export async function generateGuide(options: GenerateGuideOptions) { }, body: JSON.stringify({ keyword: term, - depth, isForce, customPrompt: prompt, - instructions, - goal, - about, + questionAndAnswers, src, }), credentials: 'include', diff --git a/src/queries/ai-guide.ts b/src/queries/ai-guide.ts index dc5822674..392b92e17 100644 --- a/src/queries/ai-guide.ts +++ b/src/queries/ai-guide.ts @@ -5,6 +5,7 @@ import { markdownToHtml, markdownToHtmlWithHighlighting, } from '../lib/markdown'; +import type { QuestionAnswerChatMessage } from '../components/ContentGenerator/QuestionAnswerChat'; export interface AIGuideDocument { _id: string; @@ -12,7 +13,6 @@ export interface AIGuideDocument { title: string; slug?: string; keyword: string; - depth: string; content: string; tokens: { prompt: number; @@ -24,6 +24,8 @@ export interface AIGuideDocument { deepDiveTopics: string[]; questions: string[]; + questionAndAnswers?: QuestionAnswerChatMessage[]; + viewCount: number; lastVisitedAt: Date; createdAt: Date;