Skip to content

Commit

Permalink
feat: allow disabling of the cache when parsing tools
Browse files Browse the repository at this point in the history
Signed-off-by: Donnie Adams <donnie@acorn.io>
  • Loading branch information
thedadams committed Aug 7, 2024
1 parent 4fd8e8a commit ba28159
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 10 deletions.
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,10 @@ validate-docs:
git diff; \
exit 1 \
;fi

create-migration:
@if [ -z "$(NAME)" ]; then \
echo "NAME must be set"; \
exit 1 \
;fi
migrate create -ext sql -dir migrations -seq $(NAME)
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ module github.com/gptscript-ai/gptscript
// This can't be upgraded until the issue with sys.daemon on Windows is resolved
go 1.22.4

replace github.com/gptscript-ai/tui => ../tui

require (
github.com/AlecAivazis/survey/v2 v2.3.7
github.com/BurntSushi/locker v0.0.0-20171006230638-a6e239ea1c69
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,6 @@ github.com/gptscript-ai/cmd v0.0.0-20240802230653-326b7baf6fcb h1:ky2J2CzBOskC7J
github.com/gptscript-ai/cmd v0.0.0-20240802230653-326b7baf6fcb/go.mod h1:DJAo1xTht1LDkNYFNydVjTHd576TC7MlpsVRl3oloVw=
github.com/gptscript-ai/go-gptscript v0.9.4-0.20240801203434-840b14393b17 h1:BTfJ6ls31Roq42lznlZnuPzRf0wrT8jT+tWcvq7wDXY=
github.com/gptscript-ai/go-gptscript v0.9.4-0.20240801203434-840b14393b17/go.mod h1:Dh6vYRAiVcyC3ElZIGzTvNF1FxtYwA07BHfSiFKQY7s=
github.com/gptscript-ai/tui v0.0.0-20240804004233-efc5673dc76e h1:OO/b8gGQi3jIpDoII+jf7fc4ssqOZdFcb9zB+QjsxRQ=
github.com/gptscript-ai/tui v0.0.0-20240804004233-efc5673dc76e/go.mod h1:KGtCo7cjH6qR6Wp6AyI1dL1R8bln8wVpdDEoopRUckY=
github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
Expand Down
5 changes: 3 additions & 2 deletions pkg/cli/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import (
)

type Parse struct {
PrettyPrint bool `usage:"Indent the json output" short:"p"`
PrettyPrint bool `usage:"Indent the json output" short:"p"`
DisableCache bool `usage:"Disable caching when retrieving remote files"`
}

func (e *Parse) Customize(cmd *cobra.Command) {
Expand All @@ -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.DisableCache)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/input/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 4 additions & 2 deletions pkg/loader/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/sdkserver/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion pkg/sdkserver/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit ba28159

Please sign in to comment.