Skip to content

Commit 6a2b694

Browse files
chore: already cached performance improvements
1 parent 3c29ebe commit 6a2b694

File tree

5 files changed

+30
-2
lines changed

5 files changed

+30
-2
lines changed

pkg/engine/cmd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func (e *Engine) runCommand(ctx Context, tool types.Tool, input string, toolCate
9696
instructions = append(instructions, inputContext.Content)
9797
}
9898
var extraEnv = []string{
99-
strings.TrimSpace(fmt.Sprintf("GPTSCRIPT_CONTEXT=%s", strings.Join(instructions, "\n"))),
99+
strings.TrimSpace("GPTSCRIPT_CONTEXT=" + strings.Join(instructions, "\n")),
100100
}
101101

102102
cmd, stop, err := e.newCommand(ctx.Ctx, extraEnv, tool, input)

pkg/env/env.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ func AppendPath(env []string, binPath string) []string {
6060
// Lookup will try to find bin in the PATH in env. It will refer to PATHEXT for Windows support.
6161
// If bin can not be resolved to anything the original bin string is returned.
6262
func Lookup(env []string, bin string) string {
63+
if strings.Contains(bin, string(filepath.Separator)) {
64+
return bin
65+
}
66+
6367
for _, env := range env {
6468
for _, prefix := range []string{"PATH=", "Path="} {
6569
suffix, ok := strings.CutPrefix(env, prefix)

pkg/gptscript/gptscript.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ func complete(opts ...Options) Options {
7575
if result.CredentialContext == "" {
7676
result.CredentialContext = "default"
7777
}
78+
if result.OpenAI.DefaultModel == "" {
79+
result.OpenAI.DefaultModel = builtin.GetDefaultModel()
80+
}
7881

7982
return result
8083
}

pkg/loader/url.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"net/http"
88
url2 "net/url"
99
"path"
10+
"regexp"
1011
"strings"
1112
"time"
1213

@@ -33,6 +34,14 @@ type cacheValue struct {
3334
Time time.Time
3435
}
3536

37+
func (c *cacheKey) isStatic() bool {
38+
return c.Repo != nil &&
39+
c.Repo.Revision != "" &&
40+
stableRef.MatchString(c.Repo.Revision)
41+
}
42+
43+
var stableRef = regexp.MustCompile("^([a-f0-9]{7,40}$|v[0-9]|[0-9])")
44+
3645
func loadURL(ctx context.Context, cache *cache.Client, base *source, name string) (*source, bool, error) {
3746
var (
3847
repo *types.Repo
@@ -47,9 +56,17 @@ func loadURL(ctx context.Context, cache *cache.Client, base *source, name string
4756
cachedValue cacheValue
4857
)
4958

59+
if cachedKey.Repo == nil {
60+
if _, rev, ok := strings.Cut(name, "@"); ok && stableRef.MatchString(rev) {
61+
cachedKey.Repo = &types.Repo{
62+
Revision: rev,
63+
}
64+
}
65+
}
66+
5067
if ok, err := cache.Get(ctx, cachedKey, &cachedValue); err != nil {
5168
return nil, false, err
52-
} else if ok && time.Since(cachedValue.Time) < CacheTimeout {
69+
} else if ok && (cachedKey.isStatic() || time.Since(cachedValue.Time) < CacheTimeout) {
5370
return cachedValue.Source, true, nil
5471
}
5572

pkg/openai/client.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ func (c *Client) ValidAuth() error {
138138
}
139139

140140
func (c *Client) Supports(ctx context.Context, modelName string) (bool, error) {
141+
if c.defaultModel != "" && c.defaultModel == modelName {
142+
return true, nil
143+
}
144+
141145
models, err := c.ListModels(ctx)
142146
if err != nil {
143147
return false, err

0 commit comments

Comments
 (0)