diff --git a/Makefile b/Makefile index e0d93a1d..5b1b6309 100644 --- a/Makefile +++ b/Makefile @@ -52,12 +52,14 @@ init-docs: docker run --rm --workdir=/docs -v $${PWD}/docs:/docs node:18-buster yarn install # Ensure docs build without errors. Makes sure generated docs are in-sync with CLI. -validate-docs: +validate-docs: gen-docs docker run --rm --workdir=/docs -v $${PWD}/docs:/docs node:18-buster yarn build - go run tools/gendocs/main.go if [ -n "$$(git status --porcelain --untracked-files=no)" ]; then \ git status --porcelain --untracked-files=no; \ echo "Encountered dirty repo!"; \ git diff; \ exit 1 \ ;fi + +gen-docs: + go run tools/gendocs/main.go \ No newline at end of file diff --git a/pkg/cli/gptscript.go b/pkg/cli/gptscript.go index 4458d87b..536e339b 100644 --- a/pkg/cli/gptscript.go +++ b/pkg/cli/gptscript.go @@ -83,7 +83,7 @@ func New() *cobra.Command { root, &Eval{gptscript: root}, &Credential{root: root}, - &Parse{}, + &Parse{gptscript: root}, &Fmt{}, &Getenv{}, &SDKServer{ diff --git a/pkg/cli/parse.go b/pkg/cli/parse.go index 8599bd97..081116c1 100644 --- a/pkg/cli/parse.go +++ b/pkg/cli/parse.go @@ -12,6 +12,7 @@ import ( type Parse struct { PrettyPrint bool `usage:"Indent the json output" short:"p"` + gptscript *GPTScript } func (e *Parse) Customize(cmd *cobra.Command) { @@ -26,7 +27,7 @@ func locationName(l string) string { } func (e *Parse) Run(_ *cobra.Command, args []string) error { - content, err := input.FromLocation(args[0]) + content, err := input.FromLocation(args[0], e.gptscript.DisableCache) if err != nil { return err } diff --git a/pkg/input/input.go b/pkg/input/input.go index 3d480431..f930753f 100644 --- a/pkg/input/input.go +++ b/pkg/input/input.go @@ -55,13 +55,13 @@ func FromFile(file string) (string, error) { } // FromLocation takes a string that can be a file path or a URL to a file and returns the content of that file. -func FromLocation(s string) (string, error) { +func FromLocation(s string, disableCache bool) (string, error) { // Attempt to read the file first, if that fails, try to load the URL. Finally, // return an error if both fail. content, err := FromFile(s) if err != nil { log.Debugf("failed to read file %s (due to %v) attempting to load the URL...", s, err) - content, err = loader.ContentFromURL(s) + content, err = loader.ContentFromURL(s, disableCache) if err != nil { return "", err } diff --git a/pkg/loader/url.go b/pkg/loader/url.go index 41400790..72970546 100644 --- a/pkg/loader/url.go +++ b/pkg/loader/url.go @@ -207,8 +207,10 @@ func getWithDefaults(req *http.Request) ([]byte, string, error) { panic("unreachable") } -func ContentFromURL(url string) (string, error) { - cache, err := cache.New() +func ContentFromURL(url string, disableCache bool) (string, error) { + cache, err := cache.New(cache.Options{ + DisableCache: disableCache, + }) if err != nil { return "", fmt.Errorf("failed to create cache: %w", err) } diff --git a/pkg/sdkserver/routes.go b/pkg/sdkserver/routes.go index 2e709e3f..c0d7a41b 100644 --- a/pkg/sdkserver/routes.go +++ b/pkg/sdkserver/routes.go @@ -227,7 +227,7 @@ func (s *server) parse(w http.ResponseWriter, r *http.Request) { if reqObject.Content != "" { out, err = parser.Parse(strings.NewReader(reqObject.Content), reqObject.Options) } else { - content, loadErr := input.FromLocation(reqObject.File) + content, loadErr := input.FromLocation(reqObject.File, reqObject.DisableCache) if loadErr != nil { logger.Errorf(loadErr.Error()) writeError(logger, w, http.StatusInternalServerError, loadErr) diff --git a/pkg/sdkserver/types.go b/pkg/sdkserver/types.go index 9736f045..ade035b2 100644 --- a/pkg/sdkserver/types.go +++ b/pkg/sdkserver/types.go @@ -86,7 +86,8 @@ type parseRequest struct { parser.Options `json:",inline"` content `json:",inline"` - File string `json:"file"` + DisableCache bool `json:"disableCache"` + File string `json:"file"` } type modelsRequest struct {