Skip to content

Commit 934a078

Browse files
authored
Fix text composition (#39)
* Fix text composition * Code formatting
1 parent 8a1a590 commit 934a078

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

tinyswallow-webgpu/src/App.jsx

+8-3
Original file line numberDiff line numberDiff line change
@@ -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 ? (

tinyswallow-webgpu/src/worker.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ async function check() {
1515
if (!adapter) {
1616
throw new Error("WebGPU is not supported (no adapter found)");
1717
}
18-
fp16_supported = adapter.features.has("shader-f16")
18+
fp16_supported = adapter.features.has("shader-f16");
1919
} catch (e) {
2020
self.postMessage({
2121
status: "error",

0 commit comments

Comments
 (0)