Skip to content

Commit 2375a7c

Browse files
committed
Added filename prefix control and tested additional translation controls
1 parent 72efa42 commit 2375a7c

File tree

2 files changed

+33
-17
lines changed

2 files changed

+33
-17
lines changed

shuffle.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,7 @@ func FindShuffleFile(name, category string, shuffleConfig ShuffleConfig) ([]byte
467467
log.Printf("[ERROR] Schemaless (6): Error getting file %#v from Shuffle backend: %s", name, err)
468468
return []byte{}, err
469469
}
470+
//log.Printf("\n\n[DEBUG] Got downloaded file data:\n%s\n\n", downloadedFile)
470471

471472
return downloadedFile, nil
472473
}

translate.go

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ func SaveQuery(inputStandard, gptTranslated string, shuffleConfig ShuffleConfig)
5454

5555
func GptTranslate(keyTokenFile, standardFormat, inputDataFormat string, shuffleConfig ShuffleConfig) (string, error) {
5656

57-
//systemMessage := fmt.Sprintf("Use the this standard format for the output, and neither add things at the start, nor subtract from the end. Only modify the keys. Add ONLY the most relevant matching key, and make sure each key has a value. It NEEDS to be a valid JSON message: %s", standardFormat)
58-
//userQuery := fmt.Sprintf(`Use the standard to translate the following input JSON data. If the key is a synonym, matching or similar between the two, add the key of the input to the value of the standard. User Input:\n%s`, inputDataFormat)
59-
60-
systemMessage := fmt.Sprintf("Ensure the output is valid JSON, and does NOT add more keys to the standard. Make sure each key in the standard has a value from the user input. If values are nested, ALWAYS add the nested value in jq format such as 'secret.version.value'. Example: If the standard is ```{\"id\": \"The id of the ticket\", \"title\": \"The ticket title\"}```, and the user input is ```{\"key\": \"12345\", \"fields:\": {\"summary\": \"The title of the ticket\"}}```, the output should be ```{\"id\": \"key\", \"title\": \"fields.summary\"}```")
57+
//inputToken := "apikey"
58+
//additionalCondition := fmt.Sprintf("If the key '%s' matches exactly to a field, add '%s' itself instead of any jq format. ", inputToken, inputToken)
59+
additionalCondition := fmt.Sprintf("")
6160

61+
systemMessage := fmt.Sprintf("Ensure the output is valid JSON, and does NOT add more keys to the standard. Make sure each key in the standard has a value from the user input. If values are nested, ALWAYS add the nested value in jq format such as 'secret.version.value'. %sExample: If the standard is ```{\"id\": \"The id of the ticket\", \"title\": \"The ticket title\"}```, and the user input is ```{\"key\": \"12345\", \"fields:\": {\"summary\": \"The title of the ticket\"}}```, the output should be ```{\"id\": \"key\", \"title\": \"fields.summary\"}```", additionalCondition)
6262

6363
userQuery := fmt.Sprintf("Translate the given user input JSON structure to a standard format. Use the values from the standard to guide you what to look for. The standard format should follow the pattern:\n\n```json\n%s\n```\n\nUser Input:\n```json\n%s\n```\n\nGenerate the standard output structure without providing the expected output.", standardFormat, inputDataFormat)
6464

@@ -762,6 +762,27 @@ func Translate(ctx context.Context, inputStandard string, inputValue []byte, inp
762762
}
763763
}
764764

765+
// FIXME: May not be important anymore
766+
// This prevents recursion inside a JSON blob
767+
// in case file reference is bad
768+
769+
// Reference key addition is a way the user can send in a key to add to the filename, as to make it unique and configurable, even with the same input/output from the actual translation
770+
skipSubstandard := false
771+
filenamePrefix := ""
772+
for _, input := range inputConfig {
773+
if input == "skip_substandard" {
774+
skipSubstandard = true
775+
break
776+
}
777+
778+
if strings.HasPrefix(strings.ToLower(input), "filename_prefix:") {
779+
input = strings.TrimPrefix(input, "filename_prefix:")
780+
if len(input) > 0 {
781+
filenamePrefix = fmt.Sprintf("%s", input)
782+
}
783+
}
784+
}
785+
765786
if shuffleConfig.URL == "" {
766787
// Check for paths
767788
fixPaths()
@@ -789,29 +810,23 @@ func Translate(ctx context.Context, inputStandard string, inputValue []byte, inp
789810
inputStandard = strings.TrimSuffix(inputStandard, ".json")
790811
}
791812

792-
//keyToken = fmt.Sprintf("%s:%s", inputStandard, keyToken)
793-
keyTokenFile := fmt.Sprintf("%s-%x", inputStandard, md5.Sum([]byte(keyToken)))
813+
keyTokenFile := fmt.Sprintf("%s%s-%x", filenamePrefix, inputStandard, md5.Sum([]byte(keyToken)))
794814
err = SaveParsedInput(keyTokenFile, returnJson, shuffleConfig)
795815
if err != nil {
796816
log.Printf("[ERROR] Schemaless: Error in SaveParsedInput for file %s: '%v'", keyTokenFile, err)
797817
return []byte{}, err
798818
}
799819

800-
// FIXME: May not be important anymore
801-
// This prevents recursion inside a JSON blob
802-
// in case file reference is bad
803-
skipSubstandard := false
804-
for _, input := range inputConfig {
805-
if input == "skip_substandard" {
806-
skipSubstandard = true
807-
break
808-
}
809-
}
810-
811820
// Check if the keyToken is already in cache and use that translation layer
812821
//log.Printf("\n\n[DEBUG] Schemaless: Getting existing structure for keyToken: '%s'\n\n", keyTokenFile)
813822
inputStructure, err := GetExistingStructure(keyTokenFile, shuffleConfig)
823+
824+
825+
log.Printf("[DEBUG] Schemaless: Found existing structure: %v", string(inputStructure))
814826
fixedOutput := FixTranslationStructure(string(inputStructure))
827+
828+
log.Printf("[DEBUG] Schemaless: Fixed output: %v", fixedOutput)
829+
815830
inputStructure = []byte(fixedOutput)
816831

817832
if err == nil {

0 commit comments

Comments
 (0)