ai-tube / src /app /api /parsers /parsePrompt.ts
jbilcke-hf's picture
jbilcke-hf HF staff
make the prompt optional
e336208
raw
history blame contribute delete
317 Bytes
export function parsePrompt(input?: any, throwIfEmpty?: boolean) {
let res = ""
try {
res = decodeURIComponent(`${input || ""}` || "").trim()
} catch (err) {}
if (!res.length) {
if (throwIfEmpty) {
throw new Error(`please provide a prompt`)
} else {
return ""
}
}
return res
}