Skip to content

Commit

Permalink
Merge branch 'main' of github.com:Shuffle/Shuffle-shared
Browse files Browse the repository at this point in the history
  • Loading branch information
0x0elliot committed Apr 12, 2024
2 parents fd43eaa + f40fa66 commit 208b222
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
12 changes: 8 additions & 4 deletions kms.go
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,8 @@ func FindNextApiStep(action Action, stepOutput []byte, additionalInfo, inputdata

// Try to fix the request based on the body
} else {
log.Printf("[ERROR] Status code is not in the 200s or 400s. Status: %d", status)

return "", action, errors.New(getBadOutputString(action, action.AppName, inputdata, string(body), status)), additionalInfo
}
}
Expand Down Expand Up @@ -614,7 +616,9 @@ func RunSelfCorrectingRequest(action Action, status int, additionalInfo, outputB
inputBody = inputBody[:len(inputBody)-2]
}

inputBody += "\n}"
if !strings.HasSuffix(strings.TrimSpace(inputBody), "}") {
inputBody += "\n}"
}

// Append previous problems too
outputBodies := outputBody
Expand All @@ -629,9 +633,9 @@ func RunSelfCorrectingRequest(action Action, status int, additionalInfo, outputB

//inputData := fmt.Sprintf("Change the fields sent to the HTTP Rest API endpoint %s for service %s to work according to the error message in the body. Learn from the error information in the paragraphs to fix the fields in the last paragraph.\n\nHTTP Status: %d\nHTTP error: %s\n\n%s\n\n%s\n\nUpdate the following fields and output as JSON in the same with modified values.\n%s", appendpoint, appname, status, outputBodies, additionalInfo, invalidFieldsString, inputBody)

inputData := fmt.Sprintf("Change the fields sent to the HTTP API for %s to be correct according to the HTTP error. \n\nHTTP Status: %d\nHTTP error: %s\n\n%s\n\nUpdate the following field(s) to have modified values to fix the error:\n%s", appname, status, outputBodies, invalidFieldsString, inputBody)
inputData := fmt.Sprintf("Change the fields sent to the HTTP API for %s to be correct according to the HTTP error. \n\nHTTP Status: %d\nHTTP error: %s\n\n%s\nUpdate the following field(s) to have modified values to fix the error:\n%s", appname, status, outputBodies, invalidFieldsString, inputBody)

log.Printf("[INFO] INPUTDATA: '%s'\n\n\n", inputData)
log.Printf("[INFO] INPUTDATA:\n\n\n\n'''%s''''\n\n\n\n", inputData)

contentOutput := ""
for {
Expand Down Expand Up @@ -697,7 +701,7 @@ func RunSelfCorrectingRequest(action Action, status int, additionalInfo, outputB
}
}

log.Printf("[INFO] Content output: %s", contentOutput)
log.Printf("[INFO] Autocorrect output: %s", contentOutput)


// Fix the params based on the contentOuput JSON
Expand Down
21 changes: 11 additions & 10 deletions shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -11792,7 +11792,7 @@ func ParsedExecutionResult(ctx context.Context, workflowExecution WorkflowExecut
// Finds ALL childnodes to set them to SKIPPED
// Remove duplicates
childNodes = FindChildNodes(workflowExecution, actionResult.Action.ID, []string{}, []string{})
log.Printf("[DEBUG][%s] FOUND %d CHILDNODES\n\n", workflowExecution.ExecutionId, len(childNodes))
//log.Printf("[DEBUG][%s] FOUND %d CHILDNODES\n\n", workflowExecution.ExecutionId, len(childNodes))
for _, nodeId := range childNodes {
log.Printf("[DEBUG][%s] Checking if node %s is already in results", workflowExecution.ExecutionId, nodeId)
if nodeId == actionResult.Action.ID {
Expand Down Expand Up @@ -20227,7 +20227,7 @@ func RunCategoryAction(resp http.ResponseWriter, request *http.Request) {
if err != nil {
log.Printf("[ERROR] Request overload for Run Category Action with IP %s", GetRequestIp(request))
resp.WriteHeader(429)
resp.Write([]byte(fmt.Sprintf(`{"success": false, "reason": "Too many requests"}`)))
resp.Write([]byte(fmt.Sprintf(`{"success": false, "reason": "Too many requests. This is an experimental AI feature and can't handle burst traffic yet."}`)))
return
}

Expand Down Expand Up @@ -20287,7 +20287,7 @@ func RunCategoryAction(resp http.ResponseWriter, request *http.Request) {
if err != nil {
log.Printf("[WARNING] Error with body read for category action: %s", err)
resp.WriteHeader(401)
resp.Write([]byte(`{"success": false}`))
resp.Write([]byte(`{"success": false, "reason": "Failed reading body of the request"}`))
return
}

Expand All @@ -20296,7 +20296,7 @@ func RunCategoryAction(resp http.ResponseWriter, request *http.Request) {
if err != nil {
log.Printf("[WARNING] Error with unmarshal tmpBody in category action: %s", err)
resp.WriteHeader(401)
resp.Write([]byte(`{"success": false}`))
resp.Write([]byte(`{"success": false, "reason": "Failed unmarshaling body of the request"}`))
return
}

Expand Down Expand Up @@ -20574,7 +20574,7 @@ func RunCategoryAction(resp http.ResponseWriter, request *http.Request) {

if value.Label != "app_authentication" && value.Label != "authenticate_app" && value.Label != "use_app" {
resp.WriteHeader(500)
resp.Write([]byte(fmt.Sprintf(`{"success": false, "reason": "Failed finding the label in app '%s'"}`, selectedApp.Name)))
resp.Write([]byte(fmt.Sprintf(`{"success": false, "reason": "Failed finding action '%s' labeled in app '%s'. If this is wrong, please contact [email protected]"}`, value.Label, strings.ReplaceAll(selectedApp.Name, "_", " "))))
return
} else {
//log.Printf("[DEBUG] NOT sending back due to label %s", value.Label)
Expand Down Expand Up @@ -21115,7 +21115,7 @@ func RunCategoryAction(resp http.ResponseWriter, request *http.Request) {
return
}

log.Printf("MISSINGFIELDS: %#v", missingFields)
log.Printf("[DEBUG] MISSINGFIELDS: %#v", missingFields)
log.Printf("[DEBUG] LOCAL AI REQUEST SENT TO %s", conversationUrl)

req.Header.Add("Authorization", request.Header.Get("Authorization"))
Expand All @@ -21132,7 +21132,6 @@ func RunCategoryAction(resp http.ResponseWriter, request *http.Request) {
return
}

log.Printf("\n\n[DEBUG] TRANSLATION REQUEST RETURNED\n\n")

defer newresp.Body.Close()
responseBody, err := ioutil.ReadAll(newresp.Body)
Expand All @@ -21143,6 +21142,8 @@ func RunCategoryAction(resp http.ResponseWriter, request *http.Request) {
return
}

log.Printf("\n\n[DEBUG] TRANSLATED REQUEST RETURNED: %s\n\n", string(responseBody))

// Unmarshal responseBody back to secondAction
newSecondAction := Action{}
err = json.Unmarshal(responseBody, &newSecondAction)
Expand Down Expand Up @@ -21244,8 +21245,8 @@ func RunCategoryAction(resp http.ResponseWriter, request *http.Request) {
inputQuery := ""
originalAppname := selectedApp.Name

// Runs attempts up to 3 times
for i := 0; i < 3; i++ {
// Runs attempts up to X times
for i := 0; i < 5; i++ {
req, err := http.NewRequest(
"POST",
apprunUrl,
Expand Down Expand Up @@ -21317,7 +21318,7 @@ func RunCategoryAction(resp http.ResponseWriter, request *http.Request) {

continue
} else {
log.Printf("[DEBUG] Error in autocorrect: %s. Params: %d", err, len(outputAction.Parameters))
log.Printf("[ERROR] Problem in autocorrect: '%s'\nParams: %d", err, len(outputAction.Parameters))
}
}

Expand Down

0 comments on commit 208b222

Please sign in to comment.