Skip to content

Commit 98719a8

Browse files
committed
feat: allow disabling of the cache when parsing tools
Signed-off-by: Donnie Adams <[email protected]>
1 parent 4fd8e8a commit 98719a8

File tree

6 files changed

+12
-8
lines changed

6 files changed

+12
-8
lines changed

Diff for: pkg/cli/gptscript.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func New() *cobra.Command {
8383
root,
8484
&Eval{gptscript: root},
8585
&Credential{root: root},
86-
&Parse{},
86+
&Parse{gptscript: root},
8787
&Fmt{},
8888
&Getenv{},
8989
&SDKServer{

Diff for: pkg/cli/parse.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212

1313
type Parse struct {
1414
PrettyPrint bool `usage:"Indent the json output" short:"p"`
15+
gptscript *GPTScript
1516
}
1617

1718
func (e *Parse) Customize(cmd *cobra.Command) {
@@ -26,7 +27,7 @@ func locationName(l string) string {
2627
}
2728

2829
func (e *Parse) Run(_ *cobra.Command, args []string) error {
29-
content, err := input.FromLocation(args[0])
30+
content, err := input.FromLocation(args[0], e.gptscript.DisableCache)
3031
if err != nil {
3132
return err
3233
}

Diff for: pkg/input/input.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@ func FromFile(file string) (string, error) {
5555
}
5656

5757
// FromLocation takes a string that can be a file path or a URL to a file and returns the content of that file.
58-
func FromLocation(s string) (string, error) {
58+
func FromLocation(s string, disableCache bool) (string, error) {
5959
// Attempt to read the file first, if that fails, try to load the URL. Finally,
6060
// return an error if both fail.
6161
content, err := FromFile(s)
6262
if err != nil {
6363
log.Debugf("failed to read file %s (due to %v) attempting to load the URL...", s, err)
64-
content, err = loader.ContentFromURL(s)
64+
content, err = loader.ContentFromURL(s, disableCache)
6565
if err != nil {
6666
return "", err
6767
}

Diff for: pkg/loader/url.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,10 @@ func getWithDefaults(req *http.Request) ([]byte, string, error) {
207207
panic("unreachable")
208208
}
209209

210-
func ContentFromURL(url string) (string, error) {
211-
cache, err := cache.New()
210+
func ContentFromURL(url string, disableCache bool) (string, error) {
211+
cache, err := cache.New(cache.Options{
212+
DisableCache: disableCache,
213+
})
212214
if err != nil {
213215
return "", fmt.Errorf("failed to create cache: %w", err)
214216
}

Diff for: pkg/sdkserver/routes.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ func (s *server) parse(w http.ResponseWriter, r *http.Request) {
227227
if reqObject.Content != "" {
228228
out, err = parser.Parse(strings.NewReader(reqObject.Content), reqObject.Options)
229229
} else {
230-
content, loadErr := input.FromLocation(reqObject.File)
230+
content, loadErr := input.FromLocation(reqObject.File, reqObject.DisableCache)
231231
if loadErr != nil {
232232
logger.Errorf(loadErr.Error())
233233
writeError(logger, w, http.StatusInternalServerError, loadErr)

Diff for: pkg/sdkserver/types.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ type parseRequest struct {
8686
parser.Options `json:",inline"`
8787
content `json:",inline"`
8888

89-
File string `json:"file"`
89+
DisableCache bool `json:"disableCache"`
90+
File string `json:"file"`
9091
}
9192

9293
type modelsRequest struct {

0 commit comments

Comments
 (0)