@@ -32,6 +32,7 @@ function App() {
3232 const [ messages , setMessages ] = useState ( [ ] ) ;
3333 const [ tps , setTps ] = useState ( null ) ;
3434 const [ numTokens , setNumTokens ] = useState ( null ) ;
35+ const [ isCompositionOn , setIsCompositionOn ] = useState ( false ) ;
3536
3637 function onEnter ( message ) {
3738 setMessages ( ( prev ) => [ ...prev , { role : "user" , content : message } ] ) ;
@@ -126,7 +127,7 @@ function App() {
126127 setMessages ( ( prev ) => {
127128 const cloned = [ ...prev ] ;
128129 const last = cloned . at ( - 1 ) ;
129- cloned [ cloned . length - 1 ] = {
130+ cloned [ cloned . length - 1 ] = {
130131 ...last ,
131132 content : last . content + output ,
132133 } ;
@@ -199,7 +200,8 @@ function App() {
199200 > </ img >
200201 < h1 className = "text-4xl font-bold mb-1" > TinySwallow WebGPU</ h1 >
201202 < 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.
203205 </ h2 >
204206 </ div >
205207
@@ -350,12 +352,15 @@ function App() {
350352 input . length > 0 &&
351353 ! isRunning &&
352354 e . key === "Enter" &&
353- ! e . shiftKey
355+ ! e . shiftKey &&
356+ ! isCompositionOn
354357 ) {
355358 e . preventDefault ( ) ; // Prevent default behavior of Enter key
356359 onEnter ( input ) ;
357360 }
358361 } }
362+ onCompositionStart = { ( ) => setIsCompositionOn ( true ) }
363+ onCompositionEnd = { ( ) => setIsCompositionOn ( false ) }
359364 onInput = { ( e ) => setInput ( e . target . value ) }
360365 />
361366 { isRunning ? (
0 commit comments