sourcegraph/cmd
Beatrix f2590cbb36
Cody Gateway: Add Gemini models to PLG and Enterprise users (#63053)
CLOSE https://github.com/sourcegraph/cody-issues/issues/211 &
https://github.com/sourcegraph/cody-issues/issues/412 &
https://github.com/sourcegraph/cody-issues/issues/412
UNBLOCK https://github.com/sourcegraph/cody/pull/4360

* Add support for Google Gemini AI models as chat completions provider
* Add new `google` package to handle Google Generative AI client
* Update `client.go` and `codygateway.go` to handle the new Google
provider
* Set default models for chat, fast chat, and completions when Google is
the configured provider
* Add gemini-pro to the allowed list

<!-- 💡 To write a useful PR description, make sure that your description
covers:
- WHAT this PR is changing:
    - How was it PREVIOUSLY.
    - How it will be from NOW on.
- WHY this PR is needed.
- CONTEXT, i.e. to which initiative, project or RFC it belongs.

The structure of the description doesn't matter as much as covering
these points, so use
your best judgement based on your context.
Learn how to write good pull request description:
https://www.notion.so/sourcegraph/Write-a-good-pull-request-description-610a7fd3e613496eb76f450db5a49b6e?pvs=4
-->


## Test plan

<!-- All pull requests REQUIRE a test plan:
https://docs-legacy.sourcegraph.com/dev/background-information/testing_principles
-->

For Enterprise instances using google as provider:

1. In your Soucegraph local instance's Site Config, add the following:

```
    "accessToken": "REDACTED",
    "chatModel": "gemini-1.5-pro-latest",
    "provider": "google",
```

Note: You can get the accessToken for Gemini API in 1Password.

2. After saving the site config with the above change, run the following
curl command:

```
curl 'https://sourcegraph.test:3443/.api/completions/stream' -i \
-X POST \
-H 'authorization: token $LOCAL_INSTANCE_TOKEN' \
--data-raw '{"messages":[{"speaker":"human","text":"Who are you?"}],"maxTokensToSample":30,"temperature":0,"stopSequences":[],"timeoutMs":5000,"stream":true,"model":"gemini-1.5-pro-latest"}'
```

3. Expected Output:

```
❯ curl 'https://sourcegraph.test:3443/.api/completions/stream' -i \
-X POST \
-H 'authorization: token <REDACTED>' \
--data-raw '{"messages":[{"speaker":"human","text":"Who are you?"}],"maxTokensToSample":30,"temperature":0,"stopSequences":[],"timeoutMs":5000,"stream":true,"model":"gemini-1.5-pro-latest"}'

HTTP/2 200
access-control-allow-credentials: true
access-control-allow-origin:
alt-svc: h3=":3443"; ma=2592000
cache-control: no-cache
content-type: text/event-stream
date: Tue, 04 Jun 2024 05:45:33 GMT
server: Caddy
server: Caddy
vary: Accept-Encoding, Authorization, Cookie, Authorization, X-Requested-With, Cookie
x-accel-buffering: no
x-content-type-options: nosniff
x-frame-options: DENY
x-powered-by: Express
x-trace: d4b1f02a3e2882a3d52331335d217b03
x-trace-span: 728ec33860d3b5e6
x-trace-url: https://sourcegraph.test:3443/-/debug/jaeger/trace/d4b1f02a3e2882a3d52331335d217b03
x-xss-protection: 1; mode=block

event: completion
data: {"completion":"I","stopReason":"STOP"}

event: completion
data: {"completion":"I am a large language model, trained by Google. \n\nThink of me as","stopReason":"STOP"}

event: completion
data: {"completion":"I am a large language model, trained by Google. \n\nThink of me as a computer program that can understand and generate human-like text.","stopReason":"MAX_TOKENS"}

event: done
data: {}
```

Verified locally:


![image](https://github.com/sourcegraph/sourcegraph/assets/68532117/2e6c914d-7a77-4484-b693-16bbc394518c)

#### Before

Cody Gateway returns `no client known for upstream provider google`

```sh
curl -X 'POST' -d '{"messages":[{"speaker":"human","text":"Who are you?"}],"maxTokensToSample":30,"temperature":0,"stopSequences":[],"timeoutMs":5000,"stream":true,"model":"google/gemini-1.5-pro-latest"}' -H 'Accept: application/json' -H 'Authorization: token $YOUR_DOTCOM_TOKEN' -H 'Content-Type: application/json' 'https://sourcegraph.com/.api/completions/stream'

event: error
data: {"error":"no client known for upstream provider google"}

event: done
data: {
```

## Changelog

<!--
1. Ensure your pull request title is formatted as: $type($domain): $what
2. Add bullet list items for each additional detail you want to cover
(see example below)
5. You can edit this after the pull request was merged, as long as
release shipping it hasn't been promoted to the public.
6. For more information, please see this how-to
https://www.notion.so/sourcegraph/Writing-a-changelog-entry-dd997f411d524caabf0d8d38a24a878c?

Audience: TS/CSE > Customers > Teammates (in that order).

Cheat sheet: $type = chore|fix|feat $domain:
source|search|ci|release|plg|cody|local|...
-->

<!--
Example:

Title: fix(search): parse quotes with the appropriate context
Changelog section:

## Changelog

- When a quote is used with regexp pattern type, then ...
- Refactored underlying code.
-->

Added support for Google as an LLM provider for Cody, with the following
models available through Cody Gateway: Gemini Pro (`gemini-pro-latest`),
Gemini 1.5 Flash (`gemini-1.5-flash-latest`), and Gemini 1.5 Pro
(`gemini-1.5-pro-latest`).
2024-06-04 23:46:36 +00:00
..
appliance appliance: split reconciler package into subpackage (#62730) 2024-05-20 16:53:14 +01:00
batcheshelper bazel: transcribe test ownership to bazel tags (#62664) 2024-05-16 15:51:16 +01:00
blobstore bazel: transcribe test ownership to bazel tags (#62664) 2024-05-16 15:51:16 +01:00
bundled-executor bazel: transcribe test ownership to bazel tags (#62664) 2024-05-16 15:51:16 +01:00
cody-gateway Cody Gateway: Add Gemini models to PLG and Enterprise users (#63053) 2024-06-04 23:46:36 +00:00
embeddings lib/background: upgrade Routine interface with context and errors (#62136) 2024-05-24 10:04:55 -04:00
enterprise-portal fix/enterpriseportal: fix registration of connectRPC handler options (#63058) 2024-06-04 09:00:01 -07:00
executor lib/background: upgrade Routine interface with context and errors (#62136) 2024-05-24 10:04:55 -04:00
executor-kubernetes bazel: transcribe test ownership to bazel tags (#62664) 2024-05-16 15:51:16 +01:00
frontend Cody Gateway: Add Gemini models to PLG and Enterprise users (#63053) 2024-06-04 23:46:36 +00:00
gitserver gitserver: Fix some cases of RevNotFound in CommitLog (#63063) 2024-06-04 23:01:02 +02:00
loadtest chore(bazel): update ownership tags to increase coverage (#63001) 2024-05-31 14:10:29 +00:00
migrator bazel: transcribe test ownership to bazel tags (#62664) 2024-05-16 15:51:16 +01:00
msp-example chore/msp-example: refactor to align with service structure best practices (#62954) 2024-05-29 09:58:43 -07:00
pings bazel: transcribe test ownership to bazel tags (#62664) 2024-05-16 15:51:16 +01:00
precise-code-intel-worker lib/background: upgrade Routine interface with context and errors (#62136) 2024-05-24 10:04:55 -04:00
repo-updater repo-updater: Hydrate schedule on startup (#62891) 2024-06-04 19:00:23 +02:00
searcher bazel: transcribe test ownership to bazel tags (#62664) 2024-05-16 15:51:16 +01:00
server feat/bazel: //cmd/{frontend,server} targets that don't include client bundle for backend integration tests (#62877) 2024-05-28 14:32:48 +01:00
symbols chore: Delete old Dockerfile and build scripts (#62922) 2024-05-27 18:52:39 +02:00
syntactic-code-intel-worker Syntactic indexing: enqueuer and scheduler (#62485) 2024-05-31 10:25:30 +01:00
telemetry-gateway lib/background: upgrade Routine interface with context and errors (#62136) 2024-05-24 10:04:55 -04:00
worker worker: add SAMS notifications subscriber (#63051) 2024-06-03 18:01:19 -04: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.