Skip to content

Commit

Permalink
feat(gpt): add proxy support
Browse files Browse the repository at this point in the history
  • Loading branch information
ernado committed Dec 9, 2023
1 parent 4e6e150 commit a488d9e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .k8s/deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ spec:
key: GITHUB_CLIENT_ID
- name: GITHUB_INSTALLATION_ID
value: "26766968"
- name: OPENAI_PROXY
valueFrom:
secretKeyRef:
name: bot
key: OPENAI_PROXY
- name: OPENAI_TOKEN
valueFrom:
secretKeyRef:
Expand Down
17 changes: 16 additions & 1 deletion internal/cmd/internal/server/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"net/http"
"net/url"
"os"
"runtime/debug"
"strconv"
Expand Down Expand Up @@ -165,9 +166,23 @@ func initApp(m *sdkapp.Metrics, lg *zap.Logger) (_ *App, rerr error) {
webhook = webhook.WithSecret(secret)
}

openaiTransport := httpTransport
if v := os.Getenv("OPENAI_PROXY"); v != "" {
proxyURL, err := url.Parse(v)
if err != nil {
return nil, errors.Wrap(err, "parse proxy URL")
}
openaiTransport = otelhttp.NewTransport(&http.Transport{
Proxy: http.ProxyURL(proxyURL),
},
otelhttp.WithTracerProvider(m.TracerProvider()),
otelhttp.WithMeterProvider(m.MeterProvider()),
)
lg.Info("Using proxy for OpenAI")
}
openaiConfig := openai.DefaultConfig(os.Getenv("OPENAI_TOKEN"))
openaiConfig.HTTPClient = &http.Client{
Transport: httpTransport,
Transport: openaiTransport,
Timeout: time.Minute,
}

Expand Down

0 comments on commit a488d9e

Please sign in to comment.