Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Cody Gateway: Add Gemini models to PLG and Enterprise users#63053

Merged
abeatrix merged 9 commits into
mainfrom
bee/gemini-plg
Jun 4, 2024
Merged

Cody Gateway: Add Gemini models to PLG and Enterprise users#63053
abeatrix merged 9 commits into
mainfrom
bee/gemini-plg

Conversation

@abeatrix

@abeatrix abeatrix commented Jun 3, 2024

Copy link
Copy Markdown
Contributor

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

Test plan

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.

  1. 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"}'
  1. 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

Before

Cody Gateway returns no client known for upstream provider google

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

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).

* Add support for Google Generative AI as a 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
@cla-bot cla-bot Bot added the cla-signed label Jun 3, 2024
@abeatrix abeatrix requested a review from chrsmith June 3, 2024 22:06
@abeatrix abeatrix changed the title CODY PLG: add support for Google Generative AI Cody Gateway: Add support for Gemini to PLG and Enterprise Jun 4, 2024
@abeatrix abeatrix requested review from emidoots and rafax June 4, 2024 06:33
@abeatrix abeatrix changed the title Cody Gateway: Add support for Gemini to PLG and Enterprise Cody Gateway: Add Gemini models to PLG and Enterprise users Jun 4, 2024
@abeatrix abeatrix marked this pull request as ready for review June 4, 2024 19:26
@abeatrix abeatrix requested review from a team June 4, 2024 19:27
Comment thread CHANGELOG.md
- A feature flag for Cody, `completions.smartContextWindow` is added and set to "enabled" by default. It allows clients to adjust the context window based on the name of the chat model. When smartContextWindow is enabled, the `completions.chatModelMaxTokens` value is ignored. ([#62802](https://github.com/sourcegraph/sourcegraph/pull/62802))
- Code Insights: When facing the "incomplete datapoints" warning, you can now use GraphQL to discover which repositories had problems. The schemas for `TimeoutDatapointAlert` and `GenericIncompleteDatapointAlert` now contain an additional `repositories` field. ([#62756](https://github.com/sourcegraph/sourcegraph/pull/62756)).
- Users will now be presented with a modal that reminds them to connect any external code host accounts that's required for permissions. Without these accounts connected, users may be unable to view repositories that they otherwise have access to. [#62983](https://github.com/sourcegraph/sourcegraph/pull/62983)
- 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`). [#63053](https://github.com/sourcegraph/sourcegraph/pull/63053)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this something we still do manually? Doesn't the "# Changelog" section of the PR take care of it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vdavid didn't know that, TIL!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was a genuine question. 😄 I saw the template in the PR, so I've started using it, but never checked whether some automated or manual process actually added my changes to the changelog. Right now I'm just blindly relying on the assumption that some process will take care of it.

@vdavid vdavid left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went through all files in detail, and TBH, it just LGTM. Saw the test coverage where there was significant logic, and that you ran this code and worked for you, so I don't have anything to add, it looks good. Great job, Bee! :)

@chrsmith chrsmith left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some nit picks and suggestions for cleanup, but this all looks good to me! :shipit:

Comment thread cmd/cody-gateway/internal/httpapi/completions/google_test.go Outdated
Comment thread internal/completions/client/google/decoder_test.go
Comment thread internal/completions/client/google/google.go Outdated
Comment thread internal/completions/client/google/google.go
Comment thread internal/completions/client/google/google.go Outdated
Comment thread internal/completions/client/google/google.go Outdated
@abeatrix

abeatrix commented Jun 4, 2024

Copy link
Copy Markdown
Contributor Author

sg start from the latest commit and verified the changes still work correctly:

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 23:44:44 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: 73f3b2564bd04916e4f10c237b93fd3d
x-trace-span: e846063737030d46
x-trace-url: https://sourcegraph.test:3443/-/debug/jaeger/trace/73f3b2564bd04916e4f10c237b93fd3d
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\nHere are some of","stopReason":"STOP"}

event: completion
data: {"completion":"I am a large language model, trained by Google. \n\nHere are some of the things I can do:\n\n**Communication and Language:**\n\n","stopReason":"MAX_TOKENS"}

event: done
data: {}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants