sourcegraph/cmd
Chris Smith 582022d301
Return model IDs from GraphQL, not model Names (#64307)
::sigh:: the problem here is super in the weeds, but ultimately this
fixes a problem introduced when using AWS Bedrock and Sourcegraph
instances using the older style "completions" config.

## The problem

AWS Bedrock has some LLM model names that contain a colon, e.g.
`anthropic.claude-3-opus-20240229-v1:0`. Cody clients connecting to
Sourcegraph instances using the older style "completions" config will
obtain the available LLM models by using GraphGL.

So the Cody client would see that the chat model is
`anthropic.claude-3-opus-20240229-v1:0`.

However, under the hood, the Sourcegraph instance will convert the site
config into the newer `modelconfig` format. And during that conversion,
we use a _different value_ for the **model ID** than what is in the site
config. (The **model name** is what is sent to the LLM API, and is
unmodified. The model ID is a stable, unique identifier but is sanitized
so that it adheres to naming rules.)

Because of this, we have a problem.

When the Cody client makes a request to the HTTP completions API with
the model name of `anthropic.claude-3-opus-20240229-v1:0` or
`anthropic/anthropic.claude-3-opus-20240229-v1:0` it fails. Because
there is no model with ID `...v1:0`. (We only have the sanitized
version, `...v1_0`.)

## The fix

There were a few ways we could fix this, but this goes with just having
the GraphQL component return the model ID instead of the model name. So
that when the Cody client passes that model ID to the completions API,
everything works as it should.

And, practically speaking, for 99.9% of cases, the model name and model
ID will be identical. We only strip out non-URL safe characters and
colons, which usually aren't used in model names.

## Potential bugs

With this fix however, there is a specific combination of { client,
server, and model name } where things could in theory break.
Specifically:

Client | Server | Modelname | Works |
--- | --- | --- | --- | 
unaware-of-modelconfig | not-using-modelconfig | standard | 🟢 [1] |
aware-of-modelconfig | not-using-modelconfig | standard | 🟢 [1] |
unaware-of-modelconfig | using-modelconfig | standard | 🟢 [1] |
aware-of-modelconfig | using-modelconfig | standard | 🟢  [3] |
unaware-of-modelconfig | not-using-modelconfig | non-standard | 🔴 [2] |
aware-of-modelconfig | not-using-modelconfig | non-standard | 🔴 [2] |
unaware-of-modelconfig | using-modelconfig | non-standard | 🔴 [2] |
aware-of-modelconfig | using-modelconfig | non-standard | 🟢  [3] |

1. If the model name is something that doesn't require sanitization,
there is no problem. The model ID will be the same as the model name,
and things will work like they do today.
2. If the model name gets sanitized, then IFF the Cody client were to
make a decision based on that exact model name, it wouldn't work.
Because it would receive the sanitized name, and not the real one. As
long as the Cody client is only passing that model name onto the
Sourcegraph backend which will recognize the sanitized model name / ID,
all is well.
3. If the client and server are new, and using model config, then this
shouldn't be a problem because the client would use a different API to
fetch the Sourcegraph instance's supported models. And within the
client, natively refer to the model ID instead of the model name.

Fixes
[PRIME-464](https://linear.app/sourcegraph/issue/PRIME-464/aws-bedrock-x-completions-config-does-not-work-if-model-name-has-a).

## Test plan

Added some unit tests.



## Changelog

NA
2024-08-06 13:28:33 -07:00
..
appliance feat(appliance): self-update can update multiple deployments (#64132) 2024-07-30 08:30:26 +00:00
batcheshelper bazel: transcribe test ownership to bazel tags (#62664) 2024-05-16 15:51:16 +01:00
blobstore chore: Remove unused TTL in object.Storage config (#63947) 2024-07-22 02:58:57 +00:00
bundled-executor bazel: transcribe test ownership to bazel tags (#62664) 2024-05-16 15:51:16 +01:00
cody-gateway feat(cody): add circuit breaker to handle timed-out requests and rate limit hits (#64133) 2024-08-05 11:38:58 +00:00
cody-gateway-config Update the default Sourcegraph-supplied LLM models (#64281) 2024-08-06 10:26:56 -07:00
customer-2315 Improving Azure errors for customer containers (#64278) 2024-08-06 01:19:09 +00:00
customer-4512 Improving Azure errors for customer containers (#64278) 2024-08-06 01:19:09 +00:00
embeddings authz: Drop requirement for installing authz providers in every service (#63743) 2024-07-31 01:23:34 +02:00
enterprise-portal feat/enterpriseportal: ignore context cancellation error in GetCodyGatewayUsage (#64016) 2024-07-24 11:50:21 -07:00
executor chore/executors: Native Kubernetes Executors default to use single job pod (#64088) 2024-07-31 08:07:06 -07:00
executor-kubernetes bazel: transcribe test ownership to bazel tags (#62664) 2024-05-16 15:51:16 +01:00
frontend Return model IDs from GraphQL, not model Names (#64307) 2024-08-06 13:28:33 -07:00
gitserver gitserver: RawDiff checks if commits exist (#64245) 2024-08-02 13:10:04 +00:00
loadtest chore(bazel): update ownership tags to increase coverage (#63001) 2024-05-31 14:10:29 +00:00
migrator chore(ci): conditionally stamp genrules (#63204) 2024-06-12 15:04:43 +02:00
msp-example msp/runtime: split contract into JobContract and ServiceContract (#63494) 2024-06-26 19:46:10 +00:00
pings msp/runtime: split contract into JobContract and ServiceContract (#63494) 2024-06-26 19:46:10 +00:00
precise-code-intel-worker authz: Drop requirement for installing authz providers in every service (#63743) 2024-07-31 01:23:34 +02:00
repo-updater chore: Remove global externalURL watcher (#64058) 2024-07-31 03:43:28 +02:00
searcher searcher: fix benchmarks (#64292) 2024-08-06 11:33:52 +02:00
server feat(frontend): do not embed frontend assets anymore (#63946) 2024-07-31 15:17:52 +02:00
sourcegraph support fast, simple sg start single-program-experimental-blame-sqs for local dev (#63435) 2024-06-24 21:12:47 +00:00
symbols feat(search): Enable improved symbol parsing for large repos (when using Rockskip) (#63988) 2024-07-31 15:27:31 -04:00
syntactic-code-intel-worker authz: Drop requirement for installing authz providers in every service (#63743) 2024-07-31 01:23:34 +02:00
telemetry-gateway chore/telemetrygateway: gracefully handle sams introspectToken cancelation (#63809) 2024-07-15 10:45:00 -07:00
worker chore: Reduce frequency of COUNT(*) on lsif_indexes (#64288) 2024-08-06 10:39:20 +02:00
README.md Reminder to keep architecture diagram in-sync (#36869) 2022-06-08 19:40:36 -07:00

This directory contains Sourcegraph services and binaries.

When a services is added, removed, or when a service's dependencies change, update our architecture diagram.