feat(cody-gateway): add support for Gemini models with context cache (#63413)

PART OF https://linear.app/sourcegraph/issue/CODY-2451
CLOSE https://linear.app/sourcegraph/issue/CODY-2513

- Add Gemini 1.5 Flash 001 and Gemini 1.5 Pro 001 models to the config
and allowed models lists
- These fixed stable versions support context caching, as noted in the
[Google Gemini API
docs](https://ai.google.dev/gemini-api/docs/caching?lang=node)


![image](https://github.com/sourcegraph/sourcegraph/assets/68532117/1857c853-7c8d-4446-a991-4bc6a39e6065)


NEXT: Implement context caching in the codebase. Right now using the
newly added models alone do not work with context caching.

<!-- 💡 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
-->

No feature changes. Adding new model to allow list.

## 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)
3. You can edit this after the pull request was merged, as long as
release shipping it hasn't been promoted to the public.
4. 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.
-->
This commit is contained in:
Beatrix 2024-07-03 09:28:13 -07:00 committed by GitHub
parent 4090f4fd17
commit 806ff434a6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 14 additions and 0 deletions

View File

@ -311,6 +311,8 @@ func (c *Config) Load() {
google.Gemini15FlashLatest,
google.Gemini15ProLatest,
google.GeminiProLatest,
google.Gemini15Flash001,
google.Gemini15Pro001,
google.Gemini15Flash,
google.Gemini15Pro,
google.GeminiPro,

View File

@ -335,6 +335,7 @@ var allCodeCompletionModels = slices.Concat([]string{"anthropic/" + anthropic.Cl
"anthropic/claude-instant-1.2",
"google/" + google.Gemini15Flash,
"google/" + google.Gemini15FlashLatest,
"google/" + google.Gemini15Flash001,
"google/" + google.GeminiPro,
"google/" + google.GeminiProLatest,
"fireworks/starcoder",
@ -377,6 +378,8 @@ func allowedModels(scope types.CompletionsFeature, isProUser bool) []string {
"google/" + google.Gemini15FlashLatest,
"google/" + google.Gemini15ProLatest,
"google/" + google.GeminiProLatest,
"google/" + google.Gemini15Flash001,
"google/" + google.Gemini15Pro001,
"google/" + google.Gemini15Flash,
"google/" + google.Gemini15Pro,
"google/" + google.GeminiPro,

View File

@ -100,6 +100,7 @@ func isAllowedCodeCompletionModel(model string) bool {
"anthropic/claude-instant-1.2-cyan",
"google/" + google.Gemini15Flash,
"google/" + google.Gemini15FlashLatest,
"google/" + google.Gemini15Flash001,
"google/" + google.GeminiPro,
"google/" + google.GeminiProLatest,
"fireworks/accounts/sourcegraph/models/starcoder-7b",
@ -132,6 +133,8 @@ func isAllowedCustomChatModel(model string, isProUser bool) bool {
"google/" + google.Gemini15FlashLatest,
"google/" + google.Gemini15ProLatest,
"google/" + google.GeminiProLatest,
"google/" + google.Gemini15Flash001,
"google/" + google.Gemini15Pro001,
"google/" + google.Gemini15Flash,
"google/" + google.Gemini15Pro,
"google/" + google.GeminiPro,

View File

@ -19,3 +19,9 @@ const GeminiPro = "gemini-pro"
const Gemini15FlashLatest = "gemini-1.5-flash-latest"
const Gemini15ProLatest = "gemini-1.5-pro-latest"
const GeminiProLatest = "gemini-pro-latest"
// Fixed stable versions
// NOTE: Only the fixed stable versions support context caching.
// Ref: https://ai.google.dev/gemini-api/docs/caching?lang=node
const Gemini15Flash001 = "gemini-1.5-flash-001"
const Gemini15Pro001 = "gemini-1.5-pro-001"