diff --git a/assets/buildspace-logo.png b/assets/buildspace-logo.png index 030570a..2000b80 100644 Binary files a/assets/buildspace-logo.png and b/assets/buildspace-logo.png differ diff --git a/package.json b/package.json index a4d9a30..6cac4f8 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,6 @@ "lint": "next lint" }, "dependencies": { - "@chakra-ui/react": "^2.4.1", "@emotion/react": "^11.10.5", "@emotion/styled": "^11.10.5", "eslint": "8.27.0", diff --git a/pages/_app.js b/pages/_app.js index b19eb75..e139a05 100644 --- a/pages/_app.js +++ b/pages/_app.js @@ -1,11 +1,6 @@ -import { ChakraProvider } from '@chakra-ui/react'; - +import './styles.css'; const App = ({ Component, pageProps }) => { - return ( - - - - ); + return ; }; export default App; diff --git a/pages/api/generate.js b/pages/api/generate.js index f3f4fcc..a0c3515 100644 --- a/pages/api/generate.js +++ b/pages/api/generate.js @@ -6,15 +6,35 @@ const configuration = new Configuration({ const openai = new OpenAIApi(configuration); +const basePromptPrefix = + 'Help me write lyrics in the style of Drake, Canadian Rapper\n'; +const finalPromptPrefix = 'Take the lyrics below and generate 5 song titles:\n'; + const generateAction = async (req, res) => { - const completion = await openai.createCompletion({ + // Run first prompt + const baseCompletion = await openai.createCompletion({ model: 'text-davinci-002', - prompt: req.body.input, + prompt: `${basePromptPrefix}${req.body.input}`, temperature: 0.7, + max_tokens: 2048, }); - const choice = completion.data.choices.pop(); - res.status(200).json({ choice }); + const baseChoice = baseCompletion.data.choices.pop(); + + // Run second prompt with prefix + const finalPrompt = `${finalPromptPrefix}${req.body.input}${baseChoice.text}`; + console.log(finalPrompt); + + const prefixCompletion = await openai.createCompletion({ + model: 'text-davinci-002', + prompt: finalPrompt, + temperature: 0.7, + max_tokens: 2048, + }); + + const finalChoice = prefixCompletion.data.choices.pop(); + + res.status(200).json({ baseChoice, finalChoice }); }; export default generateAction; diff --git a/pages/index.js b/pages/index.js index 8365435..aac220c 100644 --- a/pages/index.js +++ b/pages/index.js @@ -1,21 +1,10 @@ import { useCallback, useEffect, useState } from 'react'; import Image from 'next/image'; -import { - Box, - Text, - Flex, - VStack, - Textarea, - Link, - Kbd, - Spinner, - HStack, -} from '@chakra-ui/react'; import buildspaceLogo from '../assets/buildspace-logo.png'; const Home = () => { const [input, setInput] = useState(''); - const [finishReason, setFinishReason] = useState(''); + const [output, setOutput] = useState(''); const [isGenerating, setIsGenerating] = useState(false); const onChange = (event) => { @@ -33,150 +22,69 @@ const Home = () => { }); const data = await response.json(); - const { choice } = data; + const { baseChoice, finalChoice } = data; + + setOutput( + `Song Titles:${finalChoice.text}\n\nLyrics:\n${input}${baseChoice.text}` + ); setIsGenerating(false); - - setFinishReason(choice.finish_reason); - - if (choice.finish_reason === 'stop') { - console.log('end of the completion!'); - } - - setInput((prevState) => { - return prevState + choice.text; - }); }, [input]); - useEffect(() => { - const scratchPadText = localStorage.getItem('scratchpad'); - setInput(scratchPadText); - }, []); - - useEffect(() => { - const keydownHandler = async (event) => { - if ((event.metaKey || event.ctrlKey) && event.code === 'Enter') { - event.preventDefault(); - await generateAction(); - } - localStorage.setItem('scratchpad', input); - }; - - window.addEventListener('keydown', keydownHandler); - - return () => { - window.removeEventListener('keydown', keydownHandler); - }; - }, [input, generateAction]); - return ( - - - - - - Scratchpad - - - Write your own song, movie script, or anime in 2 minutes. - - - - {isGenerating && ( - - - - )} - {!isGenerating && finishReason === 'stop' && ( - - - Keep writing to generate more! - - - )} -