jbilcke-hf HF staff commited on
Commit
e336208
1 Parent(s): 626b143

make the prompt optional

Browse files
src/app/api/parsers/parsePrompt.ts CHANGED
@@ -1,9 +1,15 @@
1
- export function parsePrompt(input?: any) {
2
  let res = ""
3
  try {
4
  res = decodeURIComponent(`${input || ""}` || "").trim()
5
  } catch (err) {}
6
 
7
- if (!res.length) { throw new Error(`please provide a prompt`) }
 
 
 
 
 
 
8
  return res
9
  }
 
1
+ export function parsePrompt(input?: any, throwIfEmpty?: boolean) {
2
  let res = ""
3
  try {
4
  res = decodeURIComponent(`${input || ""}` || "").trim()
5
  } catch (err) {}
6
 
7
+ if (!res.length) {
8
+ if (throwIfEmpty) {
9
+ throw new Error(`please provide a prompt`)
10
+ } else {
11
+ return ""
12
+ }
13
+ }
14
  return res
15
  }
src/app/api/v1/edit/entities/route.ts CHANGED
@@ -18,7 +18,6 @@ export async function POST(req: NextRequest) {
18
  const mode = parseCompletionMode(query?.c)
19
  const turbo = parseTurbo(query?.t)
20
 
21
- // const prompt = parsePrompt(query?.p)
22
 
23
  const entityPrompts = parseClapEntityPrompts(query?.e)
24
 
 
18
  const mode = parseCompletionMode(query?.c)
19
  const turbo = parseTurbo(query?.t)
20
 
 
21
 
22
  const entityPrompts = parseClapEntityPrompts(query?.e)
23
 
src/app/api/v1/edit/story/route.ts CHANGED
@@ -21,7 +21,7 @@ export async function POST(req: NextRequest) {
21
  const qs = queryString.parseUrl(req.url || "")
22
  const query = (qs || {}).query
23
 
24
- const prompt = parsePrompt(query?.p)
25
  const mode = parseCompletionMode(query?.c)
26
  const turbo = parseTurbo(query?.t)
27
 
 
21
  const qs = queryString.parseUrl(req.url || "")
22
  const query = (qs || {}).query
23
 
24
+ const prompt = parsePrompt(query?.p, false)
25
  const mode = parseCompletionMode(query?.c)
26
  const turbo = parseTurbo(query?.t)
27
 
src/app/api/v1/search/route.ts CHANGED
@@ -19,7 +19,7 @@ export async function GET(req: NextRequest, res: NextResponse) {
19
  const mode = parseLatentSearchMode(query?.m)
20
 
21
  if (mode === "basic") {
22
- const prompt = parsePrompt(query?.p)
23
 
24
  const basicSearchResults: BasicSearchResult[] = await search({
25
  prompt,
 
19
  const mode = parseLatentSearchMode(query?.m)
20
 
21
  if (mode === "basic") {
22
+ const prompt = parsePrompt(query?.p, true)
23
 
24
  const basicSearchResults: BasicSearchResult[] = await search({
25
  prompt,