import React, { useState } from "react" import { TokenChip } from "./TokenChip" interface Word { text: string logprob: number replacements: string[] } async function checkText(text: string): Promise { const response = await fetch(`/check?text=${text}`) const data = await response.json() console.log(data) return data.words } async function checkText0(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("I just drove to the store to but eggs, but they had some.") const [mode, setMode] = useState<"edit" | "check">("edit") const [words, setWords] = useState([]) const [isLoading, setIsLoading] = useState(false) const check = async () => { setIsLoading(true) try { const checkedWords = await checkText(text) setWords(checkedWords) } finally { setIsLoading(false) setMode("check") } } const toggleMode = async () => { if (mode === "edit") { setIsLoading(true) await check() } else { setMode("edit") } } const handleReplace = async (index: number, newToken: string) => { const updatedWords = [...words] updatedWords[index].text = newToken updatedWords[index].logprob = 0 updatedWords[index].replacements = [] setWords(updatedWords) setText(updatedWords.map(w => w.text).join("")) // setMode("edit") await check() } let result if (mode === "edit") { result = (
{isLoading && }