diff --git a/pages/api/generate.js b/pages/api/generate.js index 957711a..6c2ff78 100644 --- a/pages/api/generate.js +++ b/pages/api/generate.js @@ -57,7 +57,7 @@ export default async function (req, res) { model: "text-davinci-003", prompt: generatePrompt(tripInfo), temperature: 0.7, - max_tokens: 1000 + max_tokens: 2000 }); res.status(200).json({ result: completion.data.choices[0].text }); } catch(error) { diff --git a/pages/index.js b/pages/index.js index 7b27c29..ddda41a 100644 --- a/pages/index.js +++ b/pages/index.js @@ -6,10 +6,12 @@ export default function Home() { const [placeInput, setPlaceInput] = useState(""); const [preferencesInput, setPreferencesInput] = useState(""); const [durationInput, setDurationInput] = useState(""); + const [disabled, setDisabled] = useState(false); const [result, setResult] = useState(); async function onSubmit(event) { event.preventDefault(); + setDisabled(true) try { const response = await fetch("/api/generate", { method: "POST", @@ -25,6 +27,7 @@ export default function Home() { const data = await response.json(); if (response.status !== 200) { + setDisabled(false) throw data.error || new Error(`Request failed with status ${response.status}`); } @@ -32,6 +35,7 @@ export default function Home() { setPlaceInput(""); setPreferencesInput(""); setDurationInput(""); + setDisabled(false) } catch(error) { // Consider implementing your own error handling logic here console.error(error); @@ -61,7 +65,7 @@ export default function Home() { onChange={(e) => setPlaceInput(e.target.value)} /> setPreferencesInput(e.target.value)} /> - + -
{result}
+
{result}
); diff --git a/pages/index.module.css b/pages/index.module.css index af7e127..58e7b79 100644 --- a/pages/index.module.css +++ b/pages/index.module.css @@ -66,7 +66,14 @@ text-align: center; cursor: pointer; } + +.main input[type="submit"]:disabled { + background-color: grey; + cursor: not-allowed; +} .main .result { - font-weight: bold; margin-top: 40px; + display: flex; + flex-direction: column; + width: 500px; }