import React, { useState } from "react" import { TokenChip } from "./TokenChip" interface Word { text: string logprob: number replacements: string[] } async function checkText(text: string): Promise { await new Promise(resolve => setTimeout(resolve, 1000)); const words = text.split(/\b/) return words.map(word => ({ text: word, logprob: -word.length, replacements: word.length < 4 ? [] : ["foo", "bar"] })) } // Add a new Spinner component const Spinner = () => (
); export default function App() { const [threshold, setThreshold] = useState(-5.0) const [context, setContext] = useState("") const [wordlist, setWordlist] = useState("") const [showWholePrompt, setShowWholePrompt] = useState(false) const [text, setText] = useState("The cumbersomely quick brown fox jumps over the conspicuously lazy dog.") const [mode, setMode] = useState<"edit" | "check">("edit") const [words, setWords] = useState([]) const [isLoading, setIsLoading] = useState(false) const toggleMode = async () => { if (mode === "edit") { setIsLoading(true) try { const checkedWords = await checkText(text) setWords(checkedWords) } finally { setMode("check") setIsLoading(false) } } else { setMode("edit") } } const handleReplace = (index: number, newToken: string) => { const updatedWords = [...words] updatedWords[index].text = newToken setWords(updatedWords) setText(updatedWords.map(w => w.text).join("")) setMode("edit") } let result if (mode === "edit") { result = (
{isLoading && }