@@ -55,7 +55,7 @@ const (
5555 nGenTokensColType = "INTEGER"
5656)
5757
58- func (d * CustomDataset ) downloadDataset (url string , savePath string ) error {
58+ func (d * CustomDataset ) downloadDataset (url string , path string ) error {
5959 // Set up signal handling for Ctrl+C (SIGINT)
6060 ctx , cancel := context .WithCancel (context .Background ())
6161 defer cancel ()
@@ -70,7 +70,7 @@ func (d *CustomDataset) downloadDataset(url string, savePath string) error {
7070 cancel ()
7171 }()
7272
73- out , err := os .Create (savePath )
73+ out , err := os .Create (path )
7474 if err != nil {
7575 return err
7676 }
@@ -109,7 +109,7 @@ func (d *CustomDataset) downloadDataset(url string, savePath string) error {
109109 written , err := io .Copy (out , pr )
110110 if err != nil {
111111 // Remove incomplete file
112- cerr := os .Remove (savePath )
112+ cerr := os .Remove (path )
113113 if cerr != nil {
114114 d .Logger .Error (cerr , "failed to remove incomplete file after download" )
115115 }
@@ -121,7 +121,7 @@ func (d *CustomDataset) downloadDataset(url string, savePath string) error {
121121 }
122122 // Check if file size is zero or suspiciously small
123123 if written == 0 {
124- cerr := os .Remove (savePath )
124+ cerr := os .Remove (path )
125125 if cerr != nil {
126126 d .Logger .Error (cerr , "failed to remove empty file after download" )
127127 }
@@ -130,7 +130,7 @@ func (d *CustomDataset) downloadDataset(url string, savePath string) error {
130130
131131 // Ensure file is fully flushed and closed before returning success
132132 if err := out .Sync (); err != nil {
133- cerr := os .Remove (savePath )
133+ cerr := os .Remove (path )
134134 if cerr != nil {
135135 d .Logger .Error (cerr , "failed to remove incomplete file after download" )
136136 }
@@ -279,37 +279,39 @@ func (d *CustomDataset) connectToDB(path string) error {
279279 return nil
280280}
281281
282- func (d * CustomDataset ) Init (path string , url string , savePath string ) error {
282+ func (d * CustomDataset ) Init (path string , url string ) error {
283283 d .hasWarned = false
284- if path != "" {
284+ if path != "" && url == "" {
285+ d .Logger .Info ("Using dataset from" , "path" , path )
285286 return d .connectToDB (path )
286287 }
287288 if url != "" {
288- if savePath == "" {
289+ d .Logger .Info ("Url detected" , "url" , url )
290+ if path == "" {
289291 user , err := os .UserHomeDir ()
290292 if err != nil {
291293 return fmt .Errorf ("failed to get user home directory: %w" , err )
292294 }
293- savePath = filepath .Join (user , ".llm-d" , "dataset.sqlite3" )
295+ path = filepath .Join (user , ".llm-d" , "dataset.sqlite3" )
296+ d .Logger .Info ("Using default for dataset" , "path" , path )
297+ } else {
298+ d .Logger .Info ("Using provided path for dataset" , "path" , path )
294299 }
295300
296- _ , err := os .Stat (savePath )
301+ _ , err := os .Stat (path )
297302 if err != nil {
298303 // file does not exist, download it
299- folder := filepath .Dir (savePath )
304+ folder := filepath .Dir (path )
300305 err := os .MkdirAll (folder , 0755 )
301306 if err != nil {
302307 return fmt .Errorf ("failed to create parent directory: %w" , err )
303308 }
304- d .Logger .Info ("Downloading dataset from URL" , "url" , url , "to" , savePath )
305- err = d .downloadDataset (url , savePath )
309+ err = d .downloadDataset (url , path )
306310 if err != nil {
307311 return fmt .Errorf ("failed to download dataset: %w" , err )
308312 }
309313 }
310- d .Logger .Info ("Using dataset from" , "path" , savePath )
311-
312- return d .connectToDB (savePath )
314+ return d .connectToDB (path )
313315 }
314316 return errors .New ("no dataset path or url provided" )
315317}
0 commit comments