Skip to content

Commit 81142ac

Browse files
committed
feat: allow bypassing of built-in proxy
If specific proxy environment variables are set, the built-in proxy will be bypassed. Signed-off-by: Donnie Adams <[email protected]>
1 parent 53a6ae0 commit 81142ac

File tree

6 files changed

+21
-8
lines changed

6 files changed

+21
-8
lines changed

pkg/builtin/builtin.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -695,9 +695,9 @@ func invalidArgument(input string, err error) string {
695695
return fmt.Sprintf("Failed to parse arguments %s: %v", input, err)
696696
}
697697

698-
func SysModelProviderCredential(ctx context.Context, _ []string, _ string, _ chan<- string) (string, error) {
698+
func SysModelProviderCredential(ctx context.Context, env []string, _ string, _ chan<- string) (string, error) {
699699
engineContext, _ := engine.FromContext(ctx)
700-
auth, url, err := engineContext.Engine.Model.ProxyInfo()
700+
auth, url, err := engineContext.Engine.Model.ProxyInfo(env)
701701
if err != nil {
702702
return "", err
703703
}

pkg/engine/engine.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414

1515
type Model interface {
1616
Call(ctx context.Context, messageRequest types.CompletionRequest, env []string, status chan<- types.CompletionStatus) (*types.CompletionMessage, error)
17-
ProxyInfo() (string, string, error)
17+
ProxyInfo([]string) (string, string, error)
1818
}
1919

2020
type RuntimeManager interface {

pkg/gptscript/gptscript.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ func (n noopModel) Call(_ context.Context, _ types.CompletionRequest, _ []string
317317
return nil, errors.New("unsupported")
318318
}
319319

320-
func (n noopModel) ProxyInfo() (string, string, error) {
320+
func (n noopModel) ProxyInfo([]string) (string, string, error) {
321321
return "", "", errors.New("unsupported")
322322
}
323323

pkg/llm/proxy.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,20 @@ import (
1515
"github.com/gptscript-ai/gptscript/pkg/openai"
1616
)
1717

18-
func (r *Registry) ProxyInfo() (string, string, error) {
18+
func (r *Registry) ProxyInfo(env []string) (string, string, error) {
19+
var proxyURL, proxyToken string
20+
for _, e := range env {
21+
if url, ok := strings.CutPrefix(e, "GPTSCRIPT_MODEL_PROVIDER_PROXY_URL="); ok {
22+
proxyURL = url
23+
} else if token, ok := strings.CutPrefix(e, "GPTSCRIPT_MODEL_PROVIDER_PROXY_TOKEN="); ok {
24+
proxyToken = token
25+
}
26+
}
27+
28+
if proxyToken != "" && proxyURL != "" {
29+
return proxyToken, proxyURL, nil
30+
}
31+
1932
r.proxyLock.Lock()
2033
defer r.proxyLock.Unlock()
2134

@@ -77,7 +90,7 @@ func (r *Registry) ServeHTTP(w http.ResponseWriter, req *http.Request) {
7790
return
7891
}
7992

80-
auth, targetURL := oai.ProxyInfo()
93+
auth, targetURL := oai.ProxyInfo(nil)
8194
if targetURL == "" {
8295
http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
8396
return

pkg/openai/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ func NewClient(ctx context.Context, credStore credentials.CredentialStore, opts
132132
}, nil
133133
}
134134

135-
func (c *Client) ProxyInfo() (token, urlBase string) {
135+
func (c *Client) ProxyInfo([]string) (token, urlBase string) {
136136
if c.invalidAuth {
137137
return "", ""
138138
}

pkg/tests/tester/runner.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ type Result struct {
3131
Err error
3232
}
3333

34-
func (c *Client) ProxyInfo() (string, string, error) {
34+
func (c *Client) ProxyInfo([]string) (string, string, error) {
3535
return "test-auth", "test-url", nil
3636
}
3737

0 commit comments

Comments
 (0)