Skip to content

Commit

Permalink
some more changes
Browse files Browse the repository at this point in the history
  • Loading branch information
rysloan4 committed Mar 22, 2023
1 parent bae0fdd commit 4689a41
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pages/api/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 7 additions & 3 deletions pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -25,13 +27,15 @@ 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}`);
}

setResult(data.result);
setPlaceInput("");
setPreferencesInput("");
setDurationInput("");
setDisabled(false)
} catch(error) {
// Consider implementing your own error handling logic here
console.error(error);
Expand Down Expand Up @@ -61,7 +65,7 @@ export default function Home() {
onChange={(e) => setPlaceInput(e.target.value)}
/>
<label
for="duration"
htmlFor="duration"
>How long are you going for?</label>
<input
type="text"
Expand All @@ -82,9 +86,9 @@ export default function Home() {
value={preferencesInput}
onChange={(e) => setPreferencesInput(e.target.value)}
/>
<input type="submit" value="Plan my trip" />
<input type="submit" value="Plan my trip" disabled={disabled}/>
</form>
<div className={styles.result}>{result}</div>
<body><div className={styles.result}> {result} </div></body>
</main>
</div>
);
Expand Down
9 changes: 8 additions & 1 deletion pages/index.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

1 comment on commit 4689a41

@vercel
Copy link

@vercel vercel bot commented on 4689a41 Mar 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

ai-example – ./

ai-example-sooty.vercel.app
ai-example-git-main-rysloan4.vercel.app
ai-example-rysloan4.vercel.app

Please sign in to comment.