| 12 | const [convert, setConvert] = useState(false); |
| 13 | |
| 14 | const handleSubmit = (raw = value) => { |
| 15 | const val = raw?.trim(); |
| 16 | if (chat.loading() || !val) return; |
| 17 | setValue(''); |
| 18 | const promptId = new Date().valueOf().toString(); |
| 19 | const messageId = (new Date().valueOf() + 1).toString(); |
| 20 | chat.prompt.create({ id: promptId, title: val }); |
| 21 | chat.message.create(promptId, { id: messageId, content: '' }); |
| 22 | mockSSE({ |
| 23 | message: val, |
| 24 | onopen() { |
| 25 | chat.start(promptId, messageId); |
| 26 | }, |
| 27 | onmessage(str) { |
| 28 | chat.push(promptId, messageId, str); |
| 29 | }, |
| 30 | onstop() { |
| 31 | chat.close(promptId, messageId); |
| 32 | }, |
| 33 | }); |
| 34 | }; |
| 35 | |
| 36 | useEffect(() => { |
| 37 | chat.conversation.create({ id: new Date().valueOf().toString() }); |