ai-tube / src /app /api /parsers /parseCompletionMode.ts
jbilcke-hf's picture
jbilcke-hf HF staff
improve compatibility with older clients
8b20f19
raw
history blame
574 Bytes
import { ClapCompletionMode } from "@aitube/clap"
export function parseCompletionMode(
input?: any,
defaultMode: ClapCompletionMode = ClapCompletionMode.PARTIAL
): ClapCompletionMode {
let mode = defaultMode
try {
let maybeMode = decodeURIComponent(`${input || ""}`).trim().toUpperCase()
if (!maybeMode) {
maybeMode = defaultMode
}
mode = maybeMode as ClapCompletionMode
} catch (err) {}
if (!Object.values(ClapCompletionMode).includes(mode)) {
throw new Error(`Invalid clap completion mode: "${mode}"`)
}
return mode
}