👋
【GPT3.5turbo】NextJsで動くGPT3.5turbo【#4Set Form Data】
【#4Set Form Data】
YouTube:https://youtu.be/F4UzBOj8074
今回はフォームデータを送信する部分について
実装を進めていきます。
pages/index.tsx
import { ChangeEvent, SyntheticEvent, useState } from 'react'
export default function Home() {
const [prompt, setPropmt] = useState('')
const [isLoading, setIsLoading] = useState(false)
const [logs, setLogs] = useState([])
const handleChange = (e: ChangeEvent<HTMLTextAreaElement>) => {
setPropmt(e.target.value)
}
const handleSubmit = (e: SyntheticEvent) => {
e.preventDefault()
}
return (
<main className=" flex min-h-screen flex-col items-center px-2">
<h1 className=" my-6 text-3xl font-bold tracking-tight text-white sm:text-4xl">
Hello Chat-GPT
</h1>
<div className=" max-w-xl overflow-hidden bg-gray-900 py-4 sm:py-6 lg:py-8">
<div className=" mx-auto max-w-3xl px-6 lg:px-8">
<div>
<div className=" max-w-xl lg:max-w-lg mb-3">
<h2 className="text-3xl mb-3 font-bold tracking-tight text-white sm:text-4xl">
Please Enter Your Message.
</h2>
</div>
</div>
<div>
<form
onSubmit={handleSubmit}
className="flex flex-col items-center justify-center"
>
<textarea
name="prompt"
value={prompt}
onChange={handleChange}
cols={20}
rows={4}
className=" w-full flex-auto rounded-md border-0 bg-white/5 px-3.5 py-2 text-white shadow-sm ring-1 ring-inset ring-white/10 focus:ring-2 focus:ring-inset focus:ring-indigo-500 sm:text-sm sm:leading-6"
></textarea>
<button
disabled={isLoading || !prompt}
type="submit"
className=" flex-none rounded-md bg-indigo-500 mt-3 px-3.5 py-2.5 text-sm font-semibold text-white shadow-sm hover:bg-indigo-400 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-500"
>
Send Message
</button>
</form>
</div>
</div>
</div>
</main>
)
}
Discussion