Skip to content

feat: allow bypassing of built-in proxy #900

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pkg/builtin/builtin.go
Original file line number Diff line number Diff line change
Expand Up @@ -695,9 +695,9 @@ func invalidArgument(input string, err error) string {
return fmt.Sprintf("Failed to parse arguments %s: %v", input, err)
}

func SysModelProviderCredential(ctx context.Context, _ []string, _ string, _ chan<- string) (string, error) {
func SysModelProviderCredential(ctx context.Context, env []string, _ string, _ chan<- string) (string, error) {
engineContext, _ := engine.FromContext(ctx)
auth, url, err := engineContext.Engine.Model.ProxyInfo()
auth, url, err := engineContext.Engine.Model.ProxyInfo(env)
if err != nil {
return "", err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

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

type RuntimeManager interface {
Expand Down
2 changes: 1 addition & 1 deletion pkg/gptscript/gptscript.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ func (n noopModel) Call(_ context.Context, _ types.CompletionRequest, _ []string
return nil, errors.New("unsupported")
}

func (n noopModel) ProxyInfo() (string, string, error) {
func (n noopModel) ProxyInfo([]string) (string, string, error) {
return "", "", errors.New("unsupported")
}

Expand Down
17 changes: 15 additions & 2 deletions pkg/llm/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,20 @@ import (
"github.com/gptscript-ai/gptscript/pkg/openai"
)

func (r *Registry) ProxyInfo() (string, string, error) {
func (r *Registry) ProxyInfo(env []string) (string, string, error) {
var proxyURL, proxyToken string
for _, e := range env {
if url, ok := strings.CutPrefix(e, "GPTSCRIPT_MODEL_PROVIDER_PROXY_URL="); ok {
proxyURL = url
} else if token, ok := strings.CutPrefix(e, "GPTSCRIPT_MODEL_PROVIDER_PROXY_TOKEN="); ok {
proxyToken = token
}
}

if proxyToken != "" && proxyURL != "" {
return proxyToken, proxyURL, nil
}

r.proxyLock.Lock()
defer r.proxyLock.Unlock()

Expand Down Expand Up @@ -77,7 +90,7 @@ func (r *Registry) ServeHTTP(w http.ResponseWriter, req *http.Request) {
return
}

auth, targetURL := oai.ProxyInfo()
auth, targetURL := oai.ProxyInfo(nil)
if targetURL == "" {
http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
return
Expand Down
2 changes: 1 addition & 1 deletion pkg/openai/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func NewClient(ctx context.Context, credStore credentials.CredentialStore, opts
}, nil
}

func (c *Client) ProxyInfo() (token, urlBase string) {
func (c *Client) ProxyInfo([]string) (token, urlBase string) {
if c.invalidAuth {
return "", ""
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/tests/tester/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type Result struct {
Err error
}

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

Expand Down