@@ -23,17 +23,44 @@ import (
2323 "context"
2424)
2525
26- var chosenModel = "gpt-4-turbo-preview"
26+ //var chosenModel = "gpt-4-turbo-preview"
27+ var chosenModel = "o4-mini"
2728var maxInputSize = 4000
2829
30+ func getRootFolder () string {
31+ rootFolder := ""
32+ filepath := os .Getenv ("FILE_LOCATION" )
33+ if len (filepath ) > 0 {
34+ rootFolder = filepath
35+ }
36+
37+ if len (rootFolder ) == 0 {
38+ filepath = os .Getenv ("SHUFFLE_FILE_LOCATION" )
39+ if len (filepath ) > 0 {
40+ rootFolder = filepath
41+ }
42+ }
43+
44+ if len (rootFolder ) > 0 {
45+ if ! strings .HasSuffix (rootFolder , "/" ) {
46+ rootFolder += "/"
47+ }
48+
49+ rootFolder += "schemaless/"
50+ }
51+
52+ return rootFolder
53+ }
54+
55+
2956func SaveQuery (inputStandard , gptTranslated string , shuffleConfig ShuffleConfig ) error {
3057 if len (shuffleConfig .URL ) > 0 {
3158 //return nil
3259 return AddShuffleFile (inputStandard , "translation_ai_queries" , []byte (gptTranslated ), shuffleConfig )
3360 }
3461
3562 // Write it to file in the example folder
36- filename := fmt .Sprintf ("queries /%s" , inputStandard )
63+ filename := fmt .Sprintf ("%squeries /%s" , getRootFolder () , inputStandard )
3764
3865 // Open the file
3966 f , err := os .OpenFile (filename , os .O_APPEND | os .O_CREATE | os .O_WRONLY , 0644 )
@@ -386,7 +413,7 @@ func SaveTranslation(inputStandard, gptTranslated string, shuffleConfig ShuffleC
386413 }
387414
388415 // Write it to file in the example folder
389- filename := fmt .Sprintf ("examples /%s.json" , inputStandard )
416+ filename := fmt .Sprintf ("%sexamples /%s.json" , getRootFolder () , inputStandard )
390417
391418 // Open the file
392419 f , err := os .OpenFile (filename , os .O_APPEND | os .O_CREATE | os .O_WRONLY , 0644 )
@@ -413,7 +440,7 @@ func SaveParsedInput(inputStandard string, gptTranslated []byte, shuffleConfig S
413440 }
414441
415442 // Write it to file in the example folder
416- filename := fmt .Sprintf ("input /%s" , inputStandard )
443+ filename := fmt .Sprintf ("%sinput /%s" , getRootFolder () , inputStandard )
417444
418445 // Open the file
419446 f , err := os .OpenFile (filename , os .O_APPEND | os .O_CREATE | os .O_WRONLY , 0644 )
@@ -446,7 +473,7 @@ func GetStandard(inputStandard string, shuffleConfig ShuffleConfig) ([]byte, err
446473 }
447474
448475 // Open the relevant file
449- filename := fmt .Sprintf ("standards /%s.json" , inputStandard )
476+ filename := fmt .Sprintf ("%sstandards /%s.json" , getRootFolder () , inputStandard )
450477 jsonFile , err := os .Open (filename )
451478 if err != nil {
452479 //log.Printf("[ERROR] Schemaless: Error opening file %s (4): %v", filename, err)
@@ -470,7 +497,7 @@ func GetExistingStructure(inputStandard string, shuffleConfig ShuffleConfig) ([]
470497 }
471498
472499 // Open the relevant file
473- filename := fmt .Sprintf ("examples /%s.json" , inputStandard )
500+ filename := fmt .Sprintf ("%sexamples /%s.json" , getRootFolder () , inputStandard )
474501 jsonFile , err := os .Open (filename )
475502 if err != nil {
476503 //log.Printf("[ERROR] Schemaless: Error opening file %s (5): %v", filename, err)
@@ -619,7 +646,12 @@ func fixPaths() {
619646 for _ , folder := range folders {
620647 if _ , err := os .Stat (folder ); os .IsNotExist (err ) {
621648 log .Printf ("[DEBUG] Schemaless: Folder '%s' does not exist, creating it" , folder )
622- os .Mkdir (folder , 0755 )
649+
650+ folderpath := fmt .Sprintf ("%s%s" , getRootFolder (), folder )
651+ err = os .Mkdir (folderpath , 0755 )
652+ if err != nil {
653+ log .Printf ("[ERROR] Schemaless: Error creating folder '%s': %v" , folder , err )
654+ }
623655 }
624656 }
625657
0 commit comments