diff --git a/components/generate/GenerateStoryComponent.tsx b/components/generate/GenerateStoryComponent.tsx
index 27564d0cd..f14b59718 100644
--- a/components/generate/GenerateStoryComponent.tsx
+++ b/components/generate/GenerateStoryComponent.tsx
@@ -1,8 +1,9 @@
'use-client';
import chatOperations from 'operations/chatOperations';
import { useState } from 'react';
+import GenerateStoryContextProvider, { IGenerateStoryContext } from './GenerateStoryContext';
-export default function GenerateStory() {
+export default function GenerateStoryComponent() {
const [loading, setLoading] = useState(false);
const [data, setData] = useState();
@@ -14,16 +15,22 @@ export default function GenerateStory() {
};
return (
-
-
+
+ {({ story }: IGenerateStoryContext) => {
+ return (
+
+
- {loading ? Loading...
: null}
- {JSON.stringify(data)}
-
+ {loading ? Loading...
: null}
+ {JSON.stringify(data)}
+
+ );
+ }}
+
);
}
diff --git a/components/generate/GenerateStoryContext.tsx b/components/generate/GenerateStoryContext.tsx
new file mode 100644
index 000000000..79b048c88
--- /dev/null
+++ b/components/generate/GenerateStoryContext.tsx
@@ -0,0 +1,44 @@
+'use client';
+
+import { IStory } from 'operations/chatOperations';
+import { PropsWithChildren, createContext, useContext, useMemo, useState } from 'react';
+
+export interface IGenerateStoryContext {
+ story?: IStory;
+ setStory: (story: IStory) => void;
+ images: string[];
+ setImages: (images: string[]) => void;
+}
+
+const GenerateStoryContext = createContext({
+ story: undefined,
+ setStory: () => {},
+ images: [],
+ setImages: () => {}
+});
+
+function GenerateStoryContextProvider({ children }: { children: PropsWithChildren }) {
+ const [story, setStory] = useState();
+ /*
+ Note(Benson): For now images is an array of urls where each index in the array
+ corresponds to the page number.
+ i.e., index 0 could be title, index 1 is the first page in pages, etc.
+ */
+ const [images, setImages] = useState([]);
+
+ const value = useMemo(
+ () => ({ story, setStory, images, setImages }),
+ [story, setStory, images, setImages]
+ );
+
+ return (
+
+ {typeof children === 'function' ? children(value) : children}
+
+ );
+}
+
+export const useGenerateStoryContext = (): IGenerateStoryContext =>
+ useContext(GenerateStoryContext);
+
+export default GenerateStoryContextProvider;
diff --git a/components/generate/index.ts b/components/generate/index.ts
new file mode 100644
index 000000000..1830c91c1
--- /dev/null
+++ b/components/generate/index.ts
@@ -0,0 +1,3 @@
+import GenerateStoryComponent from './GenerateStoryComponent';
+
+export default GenerateStoryComponent;
diff --git a/operations/chatOperations.ts b/operations/chatOperations.ts
index dc05d8922..2dd1efdaf 100644
--- a/operations/chatOperations.ts
+++ b/operations/chatOperations.ts
@@ -17,19 +17,19 @@ function getFunctionCallArguments(response: any) {
return JSON.parse(response.text.function_call.arguments);
}
-// export interface IStory {
-// title: string;
-// topic: string;
-// introduction: string;
-// narrativeStructure: string;
-// archetypes_characters: string;
-// pages: { text: string }[]
-// }
+export interface IStory {
+ title: string;
+ topic: string;
+ introduction: string;
+ narrativeStructure: string;
+ archetypes_characters: string;
+ pages: { text: string }[];
+}
async function createStoryAsync(
systemPrompt = DEFAULT_SYSTEM_PROMPT,
userPrompt = DEFAULT_USER_PROMPT
-): Promise {
+): Promise {
const messages = [
{
role: 'system',
@@ -42,7 +42,7 @@ async function createStoryAsync(
];
const data = await post('/api/open-ai/chat', generateRequestPayload(messages));
// const data = await post('/api/revalidate', generateRequestPayload(messages));
- return getFunctionCallArguments(data);
+ return getFunctionCallArguments(data);
}
export default { createStoryAsync };