Skip to content

Commit

Permalink
Changes the default chat model in cody to DeepSeek-V3 but only once (#…
Browse files Browse the repository at this point in the history
…6882)

Changes the default chat model in cody to DeepSeek-V3 but only once 

## Test plan
- Locally setup sourcegraph instance using `sg start
enterprise-cody-e2e`
- enable the feature flag 
<img width="859" alt="image"
src="https://github.com/user-attachments/assets/c5929a50-32e4-4a44-8fd9-0d314c16360b"
/>

- Restart cody in the debugger. You will see default model as Deepseek
but only once

NOTE: Actually setting up deepseek properly with Cody requires some
creds so feel free to DM me and I can send you the credentials but in
order to just check the model setting logic we don't need the creds
setup etc.

<!-- Required. See
https://docs-legacy.sourcegraph.com/dev/background-information/testing_principles.
-->
  • Loading branch information
arafatkatze authored Jan 30, 2025
1 parent b912145 commit dae2b0b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
1 change: 1 addition & 0 deletions lib/shared/src/experimentation/FeatureFlagProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export enum FeatureFlag {
* some standard out-of-the-box prompts like documentation and explain code prompts)
*/
CodyUnifiedPrompts = 'cody-unified-prompts',
CodyDeepSeekChat = 'cody-deepseek-chat',

/**
* For internal use only. New Prompts UI and logic is behind this feature flag
Expand Down
31 changes: 28 additions & 3 deletions lib/shared/src/models/modelsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,11 @@ export class ModelsService {

this.syncPreferencesSubscription = combineLatest(
this.modelsChanges,
featureFlagProvider.evaluatedFeatureFlag(FeatureFlag.CodyEditDefaultToGpt4oMini)
featureFlagProvider.evaluatedFeatureFlag(FeatureFlag.CodyEditDefaultToGpt4oMini),
featureFlagProvider.evaluatedFeatureFlag(FeatureFlag.CodyDeepSeekChat)
)
.pipe(
tap(([data, shouldEditDefaultToGpt4oMini]) => {
tap(([data, shouldEditDefaultToGpt4oMini, shouldChatDefaultToDeepSeek]) => {
if (data === pendingOperation) {
return
}
Expand All @@ -276,12 +277,30 @@ export class ModelsService {
FeatureFlag.CodyEditDefaultToGpt4oMini
)

// Check if this user has already been enrolled in the deepseek chat feature flag experiment.
// We only want to change their default model ONCE when they first join the A/B test.
// This ensures that:
// 1. New users in the test group get deepseek as their default model
// 2. If they later explicitly choose a different model (e.g., sonnet), we respect that choice
// 3. Their chosen preference persists across sessions and new chats
// 4. We don't override their preference every time they load the app
const isEnrolledDeepSeekChat = this.storage?.getEnrollmentHistory(
FeatureFlag.CodyDeepSeekChat
)

// Ensures that we have the gpt-4o-mini model
// we want to default to in this A/B test.
const gpt4oMini = data.primaryModels.find(
model => model?.modelRef?.modelId === 'gpt-4o-mini'
)

// Ensures that we have the deepseek model
// we want to default to in this A/B test
// The model is defined at https://sourcegraph.sourcegraph.com/github.com/sourcegraph/sourcegraph/-/blob/cmd/cody-gateway-config/dotcom_models.go?L323
const deepseekModel = data.primaryModels.find(
model => model?.id === 'fireworks::v1::deepseek-v3'
)

const allSitePrefs = this.storage?.getModelPreferences()
const currentAccountPrefs = { ...data.preferences }

Expand All @@ -292,6 +311,13 @@ export class ModelsService {
currentAccountPrefs.selected.edit = gpt4oMini.id
}

if (!isEnrolledDeepSeekChat && shouldChatDefaultToDeepSeek && deepseekModel) {
// For users enrolled in the A/B test, we'll default
// to the deepseek model when using the Chat command.
// They still can switch back to other models if they want.
currentAccountPrefs.selected.chat = deepseekModel.id
}

const updated: DefaultsAndUserPreferencesByEndpoint = {
...allSitePrefs,
[currentAuthStatus().endpoint]: currentAccountPrefs,
Expand Down Expand Up @@ -454,7 +480,6 @@ export class ModelsService {
})
)
}

public getDefaultChatModel(): Observable<ChatModel | undefined | typeof pendingOperation> {
return this.getDefaultModel(ModelUsage.Chat).pipe(
map(model => (model === pendingOperation ? pendingOperation : model?.id))
Expand Down

0 comments on commit dae2b0b

Please sign in to comment.