mirror of
https://github.com/kamranahmedse/developer-roadmap.git
synced 2025-09-03 22:32:35 +02:00
wip
This commit is contained in:
@@ -7,6 +7,8 @@ import { AIGuideContent } from './AIGuideContent';
|
|||||||
import { queryClient } from '../../stores/query-client';
|
import { queryClient } from '../../stores/query-client';
|
||||||
import { getAiGuideOptions } from '../../queries/ai-guide';
|
import { getAiGuideOptions } from '../../queries/ai-guide';
|
||||||
import { LoadingChip } from '../LoadingChip';
|
import { LoadingChip } from '../LoadingChip';
|
||||||
|
import type { QuestionAnswerChatMessage } from '../ContentGenerator/QuestionAnswerChat';
|
||||||
|
import { getQuestionAnswerChatMessages } from '../../lib/ai-questions';
|
||||||
|
|
||||||
type GenerateAIGuideProps = {
|
type GenerateAIGuideProps = {
|
||||||
onGuideSlugChange?: (guideSlug: string) => void;
|
onGuideSlugChange?: (guideSlug: string) => void;
|
||||||
@@ -26,48 +28,32 @@ export function GenerateAIGuide(props: GenerateAIGuideProps) {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const params = getUrlParams();
|
const params = getUrlParams();
|
||||||
const paramsTerm = params?.term;
|
const paramsTerm = params?.term;
|
||||||
const paramsDepth = params?.depth;
|
|
||||||
const paramsSrc = params?.src || 'search';
|
const paramsSrc = params?.src || 'search';
|
||||||
if (!paramsTerm || !paramsDepth) {
|
if (!paramsTerm) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let paramsGoal = '';
|
let questionAndAnswers: QuestionAnswerChatMessage[] = [];
|
||||||
let paramsAbout = '';
|
|
||||||
let paramsCustomInstructions = '';
|
|
||||||
|
|
||||||
const sessionId = params?.id;
|
const sessionId = params?.id;
|
||||||
if (sessionId) {
|
if (sessionId) {
|
||||||
const fineTuneData = getCourseFineTuneData(sessionId);
|
questionAndAnswers = getQuestionAnswerChatMessages(sessionId);
|
||||||
if (fineTuneData) {
|
|
||||||
paramsGoal = fineTuneData.goal;
|
|
||||||
paramsAbout = fineTuneData.about;
|
|
||||||
paramsCustomInstructions = fineTuneData.customInstructions;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
handleGenerateDocument({
|
handleGenerateDocument({
|
||||||
term: paramsTerm,
|
term: paramsTerm,
|
||||||
depth: paramsDepth,
|
|
||||||
instructions: paramsCustomInstructions,
|
|
||||||
goal: paramsGoal,
|
|
||||||
about: paramsAbout,
|
|
||||||
src: paramsSrc,
|
src: paramsSrc,
|
||||||
|
questionAndAnswers,
|
||||||
});
|
});
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const handleGenerateDocument = async (options: {
|
const handleGenerateDocument = async (options: {
|
||||||
term: string;
|
term: string;
|
||||||
depth: string;
|
|
||||||
instructions?: string;
|
|
||||||
goal?: string;
|
|
||||||
about?: string;
|
|
||||||
isForce?: boolean;
|
isForce?: boolean;
|
||||||
prompt?: string;
|
prompt?: string;
|
||||||
src?: string;
|
src?: string;
|
||||||
|
questionAndAnswers?: QuestionAnswerChatMessage[];
|
||||||
}) => {
|
}) => {
|
||||||
const { term, depth, isForce, prompt, instructions, goal, about, src } =
|
const { term, isForce, prompt, src, questionAndAnswers } = options;
|
||||||
options;
|
|
||||||
|
|
||||||
if (!isLoggedIn()) {
|
if (!isLoggedIn()) {
|
||||||
window.location.href = '/ai';
|
window.location.href = '/ai';
|
||||||
@@ -76,7 +62,6 @@ export function GenerateAIGuide(props: GenerateAIGuideProps) {
|
|||||||
|
|
||||||
await generateGuide({
|
await generateGuide({
|
||||||
term,
|
term,
|
||||||
depth,
|
|
||||||
onDetailsChange: (details) => {
|
onDetailsChange: (details) => {
|
||||||
const { guideId, guideSlug, creatorId, title } = details;
|
const { guideId, guideSlug, creatorId, title } = details;
|
||||||
|
|
||||||
@@ -86,7 +71,6 @@ export function GenerateAIGuide(props: GenerateAIGuideProps) {
|
|||||||
title,
|
title,
|
||||||
html: htmlRef.current,
|
html: htmlRef.current,
|
||||||
keyword: term,
|
keyword: term,
|
||||||
depth,
|
|
||||||
content,
|
content,
|
||||||
tokens: {
|
tokens: {
|
||||||
prompt: 0,
|
prompt: 0,
|
||||||
@@ -96,6 +80,7 @@ export function GenerateAIGuide(props: GenerateAIGuideProps) {
|
|||||||
relatedTopics: [],
|
relatedTopics: [],
|
||||||
deepDiveTopics: [],
|
deepDiveTopics: [],
|
||||||
questions: [],
|
questions: [],
|
||||||
|
questionAndAnswers,
|
||||||
viewCount: 0,
|
viewCount: 0,
|
||||||
lastVisitedAt: new Date(),
|
lastVisitedAt: new Date(),
|
||||||
createdAt: new Date(),
|
createdAt: new Date(),
|
||||||
@@ -112,12 +97,10 @@ export function GenerateAIGuide(props: GenerateAIGuideProps) {
|
|||||||
},
|
},
|
||||||
onLoadingChange: setIsLoading,
|
onLoadingChange: setIsLoading,
|
||||||
onError: setError,
|
onError: setError,
|
||||||
instructions,
|
|
||||||
goal,
|
|
||||||
about,
|
|
||||||
isForce,
|
isForce,
|
||||||
prompt,
|
prompt,
|
||||||
src,
|
src,
|
||||||
|
questionAndAnswers,
|
||||||
onHtmlChange: (html) => {
|
onHtmlChange: (html) => {
|
||||||
htmlRef.current = html;
|
htmlRef.current = html;
|
||||||
setHtml(html);
|
setHtml(html);
|
||||||
|
@@ -2,6 +2,7 @@ import { queryClient } from '../stores/query-client';
|
|||||||
import { getAiCourseLimitOptions } from '../queries/ai-course';
|
import { getAiCourseLimitOptions } from '../queries/ai-course';
|
||||||
import { readChatStream } from '../lib/chat';
|
import { readChatStream } from '../lib/chat';
|
||||||
import { markdownToHtmlWithHighlighting } from '../lib/markdown';
|
import { markdownToHtmlWithHighlighting } from '../lib/markdown';
|
||||||
|
import type { QuestionAnswerChatMessage } from '../components/ContentGenerator/QuestionAnswerChat';
|
||||||
|
|
||||||
type GuideDetails = {
|
type GuideDetails = {
|
||||||
guideId: string;
|
guideId: string;
|
||||||
@@ -12,13 +13,9 @@ type GuideDetails = {
|
|||||||
|
|
||||||
type GenerateGuideOptions = {
|
type GenerateGuideOptions = {
|
||||||
term: string;
|
term: string;
|
||||||
depth: string;
|
|
||||||
slug?: string;
|
slug?: string;
|
||||||
isForce?: boolean;
|
isForce?: boolean;
|
||||||
prompt?: string;
|
prompt?: string;
|
||||||
instructions?: string;
|
|
||||||
goal?: string;
|
|
||||||
about?: string;
|
|
||||||
onGuideSlugChange?: (guideSlug: string) => void;
|
onGuideSlugChange?: (guideSlug: string) => void;
|
||||||
onGuideChange?: (guide: string) => void;
|
onGuideChange?: (guide: string) => void;
|
||||||
onLoadingChange?: (isLoading: boolean) => void;
|
onLoadingChange?: (isLoading: boolean) => void;
|
||||||
@@ -28,26 +25,24 @@ type GenerateGuideOptions = {
|
|||||||
onStreamingChange?: (isStreaming: boolean) => void;
|
onStreamingChange?: (isStreaming: boolean) => void;
|
||||||
onDetailsChange?: (details: GuideDetails) => void;
|
onDetailsChange?: (details: GuideDetails) => void;
|
||||||
onFinish?: () => void;
|
onFinish?: () => void;
|
||||||
|
questionAndAnswers?: QuestionAnswerChatMessage[];
|
||||||
};
|
};
|
||||||
|
|
||||||
export async function generateGuide(options: GenerateGuideOptions) {
|
export async function generateGuide(options: GenerateGuideOptions) {
|
||||||
const {
|
const {
|
||||||
term,
|
term,
|
||||||
slug,
|
slug,
|
||||||
depth,
|
|
||||||
onGuideChange,
|
onGuideChange,
|
||||||
onLoadingChange,
|
onLoadingChange,
|
||||||
onError,
|
onError,
|
||||||
isForce = false,
|
isForce = false,
|
||||||
prompt,
|
prompt,
|
||||||
instructions,
|
|
||||||
goal,
|
|
||||||
about,
|
|
||||||
src = 'search',
|
src = 'search',
|
||||||
onHtmlChange,
|
onHtmlChange,
|
||||||
onStreamingChange,
|
onStreamingChange,
|
||||||
onDetailsChange,
|
onDetailsChange,
|
||||||
onFinish,
|
onFinish,
|
||||||
|
questionAndAnswers,
|
||||||
} = options;
|
} = options;
|
||||||
|
|
||||||
onLoadingChange?.(true);
|
onLoadingChange?.(true);
|
||||||
@@ -80,12 +75,9 @@ export async function generateGuide(options: GenerateGuideOptions) {
|
|||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
keyword: term,
|
keyword: term,
|
||||||
depth,
|
|
||||||
isForce,
|
isForce,
|
||||||
customPrompt: prompt,
|
customPrompt: prompt,
|
||||||
instructions,
|
questionAndAnswers,
|
||||||
goal,
|
|
||||||
about,
|
|
||||||
src,
|
src,
|
||||||
}),
|
}),
|
||||||
credentials: 'include',
|
credentials: 'include',
|
||||||
|
@@ -5,6 +5,7 @@ import {
|
|||||||
markdownToHtml,
|
markdownToHtml,
|
||||||
markdownToHtmlWithHighlighting,
|
markdownToHtmlWithHighlighting,
|
||||||
} from '../lib/markdown';
|
} from '../lib/markdown';
|
||||||
|
import type { QuestionAnswerChatMessage } from '../components/ContentGenerator/QuestionAnswerChat';
|
||||||
|
|
||||||
export interface AIGuideDocument {
|
export interface AIGuideDocument {
|
||||||
_id: string;
|
_id: string;
|
||||||
@@ -12,7 +13,6 @@ export interface AIGuideDocument {
|
|||||||
title: string;
|
title: string;
|
||||||
slug?: string;
|
slug?: string;
|
||||||
keyword: string;
|
keyword: string;
|
||||||
depth: string;
|
|
||||||
content: string;
|
content: string;
|
||||||
tokens: {
|
tokens: {
|
||||||
prompt: number;
|
prompt: number;
|
||||||
@@ -24,6 +24,8 @@ export interface AIGuideDocument {
|
|||||||
deepDiveTopics: string[];
|
deepDiveTopics: string[];
|
||||||
questions: string[];
|
questions: string[];
|
||||||
|
|
||||||
|
questionAndAnswers?: QuestionAnswerChatMessage[];
|
||||||
|
|
||||||
viewCount: number;
|
viewCount: number;
|
||||||
lastVisitedAt: Date;
|
lastVisitedAt: Date;
|
||||||
createdAt: Date;
|
createdAt: Date;
|
||||||
|
Reference in New Issue
Block a user