Skip to content

Commit 865a945

Browse files
committed
Minor changes to model and some prompts
1 parent 4ef2b24 commit 865a945

File tree

1 file changed

+43
-20
lines changed

1 file changed

+43
-20
lines changed

translate.go

Lines changed: 43 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ import (
2929
)
3030

3131
//var chosenModel = "gpt-4-turbo-preview"
32-
var chosenModel = "o4-mini"
33-
var maxInputSize = 4000
32+
var chosenModel = "gpt-5-mini"
33+
var maxInputSize = 5000
3434
var debug = os.Getenv("DEBUG") == "true"
3535

3636
func getRootFolder() string {
@@ -93,13 +93,15 @@ func GptTranslate(keyTokenFile, standardFormat, inputDataFormat string, shuffleC
9393

9494
additionalCondition := fmt.Sprintf("")
9595

96-
systemMessage := fmt.Sprintf("Ensure the output is valid JSON, and does NOT add more keys to the standard. Make sure each important key from the user input is in the standard. Empty fields in the standard are ok. 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)
96+
systemMessage := fmt.Sprintf("Translate the given user input JSON structure to the provided standard format in the jq format. Use the values from the standard to guide you what to look for. Ensure the output is valid JSON, and does NOT add more keys to the standard. Make sure each important key from the user input is in the standard. Empty fields in the standard are ok. 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:\": {\"id\": \"1234\", \"summary\": \"The title of the ticket\"}}```, the output should be ```{\"id\": \"key\", \"title\": \"fields.summary\"}. ALWAYS go deeper than the top level of the User Input and choose accurate values like \"fields.id\" instead of just \"fields\" where it fits.```", additionalCondition)
97+
// If translation is needed, you may use Liquid.
9798

9899
if debug {
99100
log.Printf("[DEBUG] Schemaless: Running GPT (1) with system message: %s", systemMessage)
100101
}
101102

102-
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)
103+
//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)
104+
userQuery := fmt.Sprintf("Standard:\n```json\n%s\n```\n\n\n\nUser Input:\n```json\n%s\n```", standardFormat, inputDataFormat)
103105

104106
if len(os.Getenv("OPENAI_API_KEY")) == 0 {
105107
return standardFormat, errors.New("OPENAI_API_KEY not set")
@@ -943,7 +945,14 @@ func handleMultiListItems(translatedInput []interface{}, parentKey string, parse
943945
// list -> subsub
944946
// maps -> childkeys
945947
// strings -> build it out.
946-
for childKey, v := range parsedValues {
948+
//for childKey, v := range parsedValues {
949+
950+
log.Printf("\n\n\nSTARTING NEW LIST\n\n\n")
951+
newParsedValues := parsedValues
952+
for childKey, _ := range newParsedValues {
953+
log.Printf("\n\nCHILDKEY START (%d): %#v\n\n", childIndex, childKey)
954+
v := parsedValues[childKey]
955+
947956
if val, ok := v.(map[string]interface{}); ok {
948957
// By passing in translatedInput we allow child objects to modify the parent?
949958
newKey := fmt.Sprintf("%s.%s", parentKey, childKey)
@@ -1010,8 +1019,8 @@ func handleMultiListItems(translatedInput []interface{}, parentKey string, parse
10101019
}
10111020

10121021
// Reference Item in the child list
1022+
updated := false
10131023
firstItem := modificationList[0]
1014-
var found bool
10151024
for cnt, listValue := range unmarshalledList {
10161025
if cnt >= len(modificationList) {
10171026
modificationList = append(modificationList, firstItem)
@@ -1022,23 +1031,35 @@ func handleMultiListItems(translatedInput []interface{}, parentKey string, parse
10221031
newKey := fmt.Sprintf("%s.%s", newParentKey, childKey)
10231032
newKey = strings.SplitN(newKey, ".", 2)[1]
10241033

1025-
//cntItem := modificationList[cnt].(map[string]interface{})
1026-
//if len(listValue) > 10 {
1027-
// log.Printf("Setting value %#v for key '%s' in modificationList[%d]", listValue, newKey, cnt)
1028-
//}
1029-
1030-
log.Printf("Listvalue to put in index '%d': %#v", childIndex, listValue)
10311034
newModList := modificationList[cnt].(map[string]interface{})
1035+
marshalledMap, err := json.Marshal(newModList)
1036+
if err == nil {
1037+
comparisonString := fmt.Sprintf(`"%s":"schemaless_list[`, newKey)
1038+
if !strings.Contains(string(marshalledMap), comparisonString) {
1039+
continue
10321040

1033-
newModList, found = setNestedMap(newModList, newKey, listValue)
1034-
modificationList[cnt] = newModList
1035-
if !found {
1036-
if debug {
1037-
log.Printf("[ERROR] Schemaless: Could not set nested map for key '%s' with value '%s'. Count: %#v", newKey, listValue, cnt)
10381041
}
1042+
1043+
log.Printf("Listvalue to put '%s' in key '%s': %s", listValue, newKey, string(marshalledMap))
10391044
}
1045+
1046+
1047+
newModList, _ = setNestedMap(newModList, newKey, listValue)
1048+
log.Printf("NEW VALUE: %#v", newModList)
1049+
modificationList[cnt] = newModList
1050+
updated = true
1051+
//break
10401052
}
10411053

1054+
// FIXME: Something with parsedValues being overridden
1055+
// every single time. Prolly in setNestedMap() or something
1056+
if updated {
1057+
parsedValues = modificationList[childIndex].(map[string]interface{})
1058+
}
1059+
1060+
marshalled, _ := json.MarshalIndent(modificationList, "", "\t")
1061+
log.Printf("MARSHALLED (%d): %s.", listDepth, string(marshalled))
1062+
10421063
if listDepth > 0 {
10431064
// Updates the child & here
10441065
// This shit also needs recursion.. gahh
@@ -1056,7 +1077,7 @@ func handleMultiListItems(translatedInput []interface{}, parentKey string, parse
10561077
log.Printf("[DEBUG] Potential LOOP issue: KEY TO PUT IN: %#v. '%#v' -> %#v", oldParentKey, parsedValues, modificationList)
10571078
}
10581079

1059-
updated := false
1080+
updated = false
10601081
for inputKey, _ := range translatedInput {
10611082
//FIXME: Need to NOT update the index unless there is a schemaless_list[] in the key in question
10621083
newMap := translatedInput[inputKey].(map[string]interface{})
@@ -1090,17 +1111,19 @@ func handleMultiListItems(translatedInput []interface{}, parentKey string, parse
10901111

10911112
translatedInput = append(translatedInput, map[string]interface{}{})
10921113
newMap := translatedInput[len(translatedInput)-1].(map[string]interface{})
1093-
newMap, found = setNestedMap(newMap, oldParentKey, modificationList)
1114+
newMap, _ = setNestedMap(newMap, oldParentKey, modificationList)
10941115
translatedInput[len(translatedInput)-1] = newMap
10951116
}
10961117

10971118
parsedValues = modificationList[childIndex].(map[string]interface{})
10981119

10991120
} else {
1121+
parsedValues = modificationList[childIndex].(map[string]interface{})
1122+
11001123
translatedInput = modificationList
11011124
}
11021125

1103-
marshalled, _ := json.MarshalIndent(translatedInput, "", "\t")
1126+
marshalled, _ = json.MarshalIndent(translatedInput, "", "\t")
11041127
log.Printf("MARSHALLED (%d): %s.", listDepth, string(marshalled))
11051128
//translatedInput = modificationList
11061129

0 commit comments

Comments
 (0)