Spaces:
Build error
Build error
Refactor TextGeneration.tsx to handle input state locally
Browse files
components/app/TextGeneration.tsx
CHANGED
|
@@ -5,12 +5,18 @@ import { useChat } from '@ai-sdk/react';
|
|
| 5 |
|
| 6 |
export default function TextGeneration() {
|
| 7 |
const [model, setModel] = useState('alias-code');
|
| 8 |
-
const
|
|
|
|
| 9 |
api: '/api/text-generation',
|
| 10 |
body: {
|
| 11 |
model,
|
| 12 |
},
|
|
|
|
| 13 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
return (
|
| 16 |
<div className="flex flex-col w-full max-w-md py-24 mx-auto stretch">
|
|
@@ -40,7 +46,7 @@ export default function TextGeneration() {
|
|
| 40 |
<form onSubmit={handleSubmit} className="flex-shrink-0">
|
| 41 |
<input
|
| 42 |
className="w-full max-w-md p-2 border border-gray-300 rounded shadow-xl"
|
| 43 |
-
value={
|
| 44 |
placeholder="Say something..."
|
| 45 |
onChange={handleInputChange}
|
| 46 |
/>
|
|
|
|
| 5 |
|
| 6 |
export default function TextGeneration() {
|
| 7 |
const [model, setModel] = useState('alias-code');
|
| 8 |
+
const [inputValue, setInputValue] = useState('');
|
| 9 |
+
const { messages, handleSubmit } = useChat({
|
| 10 |
api: '/api/text-generation',
|
| 11 |
body: {
|
| 12 |
model,
|
| 13 |
},
|
| 14 |
+
initialInput: inputValue,
|
| 15 |
});
|
| 16 |
+
|
| 17 |
+
const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
| 18 |
+
setInputValue(e.target.value);
|
| 19 |
+
};
|
| 20 |
|
| 21 |
return (
|
| 22 |
<div className="flex flex-col w-full max-w-md py-24 mx-auto stretch">
|
|
|
|
| 46 |
<form onSubmit={handleSubmit} className="flex-shrink-0">
|
| 47 |
<input
|
| 48 |
className="w-full max-w-md p-2 border border-gray-300 rounded shadow-xl"
|
| 49 |
+
value={inputValue}
|
| 50 |
placeholder="Say something..."
|
| 51 |
onChange={handleInputChange}
|
| 52 |
/>
|