@@ -32,6 +32,7 @@ function App() {
32
32
const [ messages , setMessages ] = useState ( [ ] ) ;
33
33
const [ tps , setTps ] = useState ( null ) ;
34
34
const [ numTokens , setNumTokens ] = useState ( null ) ;
35
+ const [ isCompositionOn , setIsCompositionOn ] = useState ( false ) ;
35
36
36
37
function onEnter ( message ) {
37
38
setMessages ( ( prev ) => [ ...prev , { role : "user" , content : message } ] ) ;
@@ -126,7 +127,7 @@ function App() {
126
127
setMessages ( ( prev ) => {
127
128
const cloned = [ ...prev ] ;
128
129
const last = cloned . at ( - 1 ) ;
129
- cloned [ cloned . length - 1 ] = {
130
+ cloned [ cloned . length - 1 ] = {
130
131
...last ,
131
132
content : last . content + output ,
132
133
} ;
@@ -199,7 +200,8 @@ function App() {
199
200
> </ img >
200
201
< h1 className = "text-4xl font-bold mb-1" > TinySwallow WebGPU</ h1 >
201
202
< h2 className = "font-semibold" >
202
- A compact Japanese language model that runs locally in your browser with WebGPU acceleration.
203
+ A compact Japanese language model that runs locally in your
204
+ browser with WebGPU acceleration.
203
205
</ h2 >
204
206
</ div >
205
207
@@ -350,12 +352,15 @@ function App() {
350
352
input . length > 0 &&
351
353
! isRunning &&
352
354
e . key === "Enter" &&
353
- ! e . shiftKey
355
+ ! e . shiftKey &&
356
+ ! isCompositionOn
354
357
) {
355
358
e . preventDefault ( ) ; // Prevent default behavior of Enter key
356
359
onEnter ( input ) ;
357
360
}
358
361
} }
362
+ onCompositionStart = { ( ) => setIsCompositionOn ( true ) }
363
+ onCompositionEnd = { ( ) => setIsCompositionOn ( false ) }
359
364
onInput = { ( e ) => setInput ( e . target . value ) }
360
365
/>
361
366
{ isRunning ? (
0 commit comments