Trivial additions (#63601)

Couple of trivial changes I teased out of some stacked PRs.

- There were a couple of codepaths where we returned a non-200 in the
Completions API but didn't have any logging statements.
- Adds the `ProviderOverride::DisplayName` field. This will allow
Sourcegraph admins who provide custom providers the ability to give them
friendly names. (So that this information is available so it can be more
useful than the raw ID.)

Re: `ProviderOverride.DisplayName`, I don't expect this to be a required
field. Or even used very often. But when debugging things, it seemed
more helpful than just the opaque provider string like
`anthropic-via-sourcegraph` or `anthropic-via-aws-bedrock`.

## Test plan

NA

## Changelog

NA
This commit is contained in:
Chris Smith 2024-07-03 09:06:17 -07:00 committed by GitHub
parent 9ecc6e9444
commit 5e516faa2b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 5 deletions

View File

@ -85,12 +85,15 @@ func newCompletionsHandler(
}
var version types.CompletionsVersion
versionParam := r.URL.Query().Get("api-version")
if versionParam == "" {
switch versionParam := r.URL.Query().Get("api-version"); versionParam {
case "":
version = types.CompletionsVersionLegacy
} else if versionParam == "1" {
case "1":
version = types.CompletionsV1
} else {
default:
logger.Warn(
"blocking request because unrecognized CompletionsVersion API param",
log.String("version", versionParam))
http.Error(w, "Unsupported API Version (Please update your client)", http.StatusNotAcceptable)
return
}
@ -110,6 +113,7 @@ func newCompletionsHandler(
// JSON payload. And just have a zero-value CompletionRequestParameters, e.g. no prompt.
var requestParams types.CodyCompletionRequestParameters
if err := json.NewDecoder(r.Body).Decode(&requestParams); err != nil {
logger.Warn("malformed CodyCompletionRequestParameters", log.Error(err))
http.Error(w, "could not decode request body", http.StatusBadRequest)
return
}

View File

@ -55,7 +55,8 @@ type DefaultModelConfig struct {
// ProviderOverride is how a Sourcegraph admin would describe a `Provider` within
// the site-configuration.
type ProviderOverride struct {
ID ProviderID `json:"id"`
ID ProviderID `json:"id"`
DisplayName string `json:"displayName"`
ClientSideConfig *ClientSideProviderConfig `json:"clientSideConfig,omitempty"`
ServerSideConfig *ServerSideProviderConfig `json:"serverSideConfig,omitempty"`