File size: 781 Bytes
f27679f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { deleteFile } from "@/huggingface/hub/src"

import { getCredentials } from "./getCredentials"

export async function deleteFileFromDataset({
  repo,
  path,
  apiKey,
  neverThrow = false
}: {
  repo: string

  path: string

  apiKey?: string

  /**
   * If set to true, this function will never throw an exception
   * this is useful in workflow where we don't care about what happened
   * 
   * False by default
   */
  neverThrow?: boolean
}): Promise<boolean> {
  try {
    const { credentials } = await getCredentials(apiKey)

    await deleteFile({
      repo,
      path,
      credentials
    })
    return true
  } catch (err) {
    if (neverThrow) {
      console.error(`deleteFileFromDataset():`, err)
      return false
    } else {
      throw err
    }
  }
}