llmproxy: Make dotcom API URL configurable (#51629)

This commit is contained in:
Erik Seliger 2023-05-10 02:56:12 +02:00 committed by GitHub
parent cb3f8ab1de
commit 554c2f63a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 46 additions and 8 deletions

View File

@ -11,8 +11,6 @@ import (
"go.opentelemetry.io/otel/trace"
)
const endpoint = "https://sourcegraph.com/.api/graphql"
// NewClient returns a new GraphQL client for the Sourcegraph.com API authenticated
// with the given Sourcegraph access token.
//
@ -27,7 +25,7 @@ const endpoint = "https://sourcegraph.com/.api/graphql"
// println(resp.GetDotcom().ProductSubscriptionByAccessToken.LlmProxyAccess.Enabled)
//
// The client generator automatically ensures we're up-to-date with the GraphQL schema.
func NewClient(token string) graphql.Client {
func NewClient(endpoint, token string) graphql.Client {
return &tracedClient{graphql.NewClient(endpoint, &http.Client{
Transport: &tokenAuthTransport{
token: token,

View File

@ -1,6 +1,7 @@
package shared
import (
"net/url"
"time"
"github.com/sourcegraph/sourcegraph/internal/env"
@ -12,6 +13,7 @@ type Config struct {
Address string
Dotcom struct {
URL string
AccessToken string
}
@ -27,7 +29,17 @@ type Config struct {
func (c *Config) Load() {
c.Address = c.Get("LLM_PROXY_ADDR", ":9992", "Address to serve LLM proxy on.")
c.Dotcom.AccessToken = c.Get("LLM_PROXY_DOTCOM_ACCESS_TOKEN", "", "The Sourcegraph.com access token to be used.")
c.Dotcom.URL = c.Get("LLM_PROXY_DOTCOM_API_URL", "https://sourcegraph.com/.api/graphql", "Custom override for the dotcom API endpoint")
c.Anthropic.AccessToken = c.Get("LLM_PROXY_ANTHROPIC_ACCESS_TOKEN", "", "The Anthropic access token to be used.")
c.AllowAnonymous = c.GetBool("LLM_PROXY_ALLOW_ANONYMOUS", "false", "Allow anonymous access to LLM proxy.")
c.SourcesSyncInterval = c.GetInterval("LLM_PROXY_SOURCES_SYNC_INTERVAL", "2m", "The interval at which to sync actor sources.")
}
func (c *Config) Validate() error {
_, err := url.Parse(c.Dotcom.URL)
if err != nil {
return err
}
return nil
}

View File

@ -47,7 +47,7 @@ func Main(ctx context.Context, obctx *observation.Context, ready service.ReadyFu
productsubscription.NewSource(
obctx.Logger,
rcache.New("product-subscriptions"),
dotcom.NewClient(config.Dotcom.AccessToken)),
dotcom.NewClient(config.Dotcom.URL, config.Dotcom.AccessToken)),
}
// Set up our handler chain, which is run from the bottom up

View File

@ -396,6 +396,11 @@ commands:
go build -gcflags="$GCFLAGS" -o .bin/llm-proxy github.com/sourcegraph/sourcegraph/enterprise/cmd/llm-proxy
checkBinary: .bin/llm-proxy
env:
LLM_PROXY_ANTHROPIC_ACCESS_TOKEN: foobar
LLM_PROXY_DOTCOM_ACCESS_TOKEN: foobar
LLM_PROXY_DOTCOM_API_URL: https://sourcegraph.test:3443/.api/graphql
SRC_LOG_LEVEL: dbug
watch:
- lib
- internal
@ -1118,6 +1123,7 @@ commandsets:
- zoekt-web-0
- zoekt-web-1
- caddy
# If you modify this command set, please consider also updating the dotcom runset.
enterprise: &enterprise_set
requiresDevPrivate: true
checks:
@ -1152,7 +1158,32 @@ commandsets:
EXTSVC_CONFIG_FILE: ''
dotcom:
<<: *enterprise_set
# This is 95% the enterprise runset, with the addition of LLM-proxy.
requiresDevPrivate: true
checks:
- docker
- redis
- postgres
- git
commands:
- frontend
- worker
- repo-updater
- web
- gitserver-0
- gitserver-1
- searcher
- symbols
- caddy
- docsite
- syntax-highlighter
- github-proxy
- zoekt-index-0
- zoekt-index-1
- zoekt-web-0
- zoekt-web-1
- blobstore
- llm-proxy
env:
SOURCEGRAPHDOTCOM_MODE: true
@ -1426,9 +1457,6 @@ commandsets:
- redis
commands:
- llm-proxy
env:
LLM_PROXY_ANTHROPIC_ACCESS_TOKEN: foobar
LLM_PROXY_DOTCOM_ACCESS_TOKEN: foobar
tests:
# These can be run with `sg test [name]`