Skip to content

Commit 1226edb

Browse files
authored
fix: openapi: return validation errors to the LLM; improve confirmation prompt (#805)
Signed-off-by: Grant Linville <[email protected]>
1 parent 8bbb029 commit 1226edb

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

pkg/openapi/run.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ func Run(operationID, defaultHost, args string, t *openapi3.T, envs []string) (s
4242
}
4343

4444
if !validationResult.Valid() {
45-
return "", false, fmt.Errorf("invalid arguments for operation %s: %s", operationID, validationResult.Errors())
45+
// We don't return an error here because we want the LLM to be able to maintain control and try again.
46+
return fmt.Sprintf("invalid arguments for operation %s: %s", operationID, validationResult.Errors()), true, nil
4647
}
4748

4849
// Construct and execute the HTTP request.

pkg/types/toolstring.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package types
33
import (
44
"encoding/json"
55
"fmt"
6+
"os"
67
"path/filepath"
78
"strings"
89
)
@@ -76,6 +77,11 @@ func ToSysDisplayString(id string, args map[string]string) (string, error) {
7677
return fmt.Sprintf("Writing `%s`", args["filename"]), nil
7778
case "sys.context", "sys.stat", "sys.getenv", "sys.abort", "sys.chat.current", "sys.chat.finish", "sys.chat.history", "sys.echo", "sys.prompt", "sys.time.now", "sys.model.provider.credential":
7879
return "", nil
80+
case "sys.openapi":
81+
if os.Getenv("GPTSCRIPT_OPENAPI_REVAMP") == "true" && args["operation"] != "" {
82+
return fmt.Sprintf("Running API operation `%s` with arguments %s", args["operation"], args["args"]), nil
83+
}
84+
fallthrough
7985
default:
8086
return "", fmt.Errorf("unknown tool for display string: %s", id)
8187
}

0 commit comments

Comments
 (0)