Skip to content

Commit ba28159

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

File tree

8 files changed

+21
-10
lines changed

8 files changed

+21
-10
lines changed

Makefile

+7
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,10 @@ validate-docs:
6161
git diff; \
6262
exit 1 \
6363
;fi
64+
65+
create-migration:
66+
@if [ -z "$(NAME)" ]; then \
67+
echo "NAME must be set"; \
68+
exit 1 \
69+
;fi
70+
migrate create -ext sql -dir migrations -seq $(NAME)

go.mod

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ module github.com/gptscript-ai/gptscript
33
// This can't be upgraded until the issue with sys.daemon on Windows is resolved
44
go 1.22.4
55

6+
replace github.com/gptscript-ai/tui => ../tui
7+
68
require (
79
github.com/AlecAivazis/survey/v2 v2.3.7
810
github.com/BurntSushi/locker v0.0.0-20171006230638-a6e239ea1c69

go.sum

-2
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,6 @@ github.com/gptscript-ai/cmd v0.0.0-20240802230653-326b7baf6fcb h1:ky2J2CzBOskC7J
173173
github.com/gptscript-ai/cmd v0.0.0-20240802230653-326b7baf6fcb/go.mod h1:DJAo1xTht1LDkNYFNydVjTHd576TC7MlpsVRl3oloVw=
174174
github.com/gptscript-ai/go-gptscript v0.9.4-0.20240801203434-840b14393b17 h1:BTfJ6ls31Roq42lznlZnuPzRf0wrT8jT+tWcvq7wDXY=
175175
github.com/gptscript-ai/go-gptscript v0.9.4-0.20240801203434-840b14393b17/go.mod h1:Dh6vYRAiVcyC3ElZIGzTvNF1FxtYwA07BHfSiFKQY7s=
176-
github.com/gptscript-ai/tui v0.0.0-20240804004233-efc5673dc76e h1:OO/b8gGQi3jIpDoII+jf7fc4ssqOZdFcb9zB+QjsxRQ=
177-
github.com/gptscript-ai/tui v0.0.0-20240804004233-efc5673dc76e/go.mod h1:KGtCo7cjH6qR6Wp6AyI1dL1R8bln8wVpdDEoopRUckY=
178176
github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA=
179177
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
180178
github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=

pkg/cli/parse.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import (
1111
)
1212

1313
type Parse struct {
14-
PrettyPrint bool `usage:"Indent the json output" short:"p"`
14+
PrettyPrint bool `usage:"Indent the json output" short:"p"`
15+
DisableCache bool `usage:"Disable caching when retrieving remote files"`
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.DisableCache)
3031
if err != nil {
3132
return err
3233
}

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
}

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
}

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)

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)