Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default to anthropic/claude-3.5-sonnet in code mode #2081

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
8 changes: 8 additions & 0 deletions packages/host/app/components/ai-assistant/panel.gts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import { aiBotUsername } from '@cardstack/runtime-common';

import ENV from '@cardstack/host/config/environment';

import OperatorModeStateService from '@cardstack/host/services/operator-mode-state-service';

import AddSkillsToRoomCommand from '../../commands/add-skills-to-room';
import CreateAIAssistantRoomCommand from '../../commands/create-ai-assistant-room';
import { Message } from '../../lib/matrix-classes/message';
Expand All @@ -40,6 +42,8 @@ import RenameSession from '../ai-assistant/rename-session';
import Room from '../matrix/room';
import DeleteModal from '../operator-mode/delete-modal';

import { Submodes } from '../submode-switcher';

import assistantIcon from './ai-assist-icon.webp';

import type MatrixService from '../../services/matrix-service';
Expand Down Expand Up @@ -368,6 +372,7 @@ export default class AiAssistantPanel extends Component<Signature> {
@service private declare monacoService: MonacoService;
@service private declare router: RouterService;
@service private declare commandService: CommandService;
@service private declare operatorModeStateService: OperatorModeStateService;

@tracked private isShowingPastSessions = false;
@tracked private roomToRename: SessionRoomData | undefined = undefined;
Expand Down Expand Up @@ -545,6 +550,9 @@ export default class AiAssistantPanel extends Component<Signature> {
@action
private enterRoom(roomId: string, hidePastSessionsList = true) {
this.matrixService.currentRoomId = roomId;
if (this.operatorModeStateService.state.submode === Submodes.Code) {
this.matrixService.setLLMModelForCodeMode();
}
if (hidePastSessionsList) {
this.hidePastSessions();
}
Expand Down
3 changes: 3 additions & 0 deletions packages/host/app/resources/room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,9 @@ export class RoomResource extends Resource<Args> {
}

activateLLM(model: string) {
if (this.activeLLM === model) {
return;
}
this._activeLLM = model;
this.activateLLMTask.perform(model);
}
Expand Down
20 changes: 20 additions & 0 deletions packages/host/app/services/matrix-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import {
APP_BOXEL_REALMS_EVENT_TYPE,
APP_BOXEL_ACTIVE_LLM,
LEGACY_APP_BOXEL_REALMS_EVENT_TYPE,
DEFAULT_LLM_LIST,
} from '@cardstack/runtime-common/matrix-constants';

import {
Expand Down Expand Up @@ -1337,6 +1338,25 @@ export default class MatrixService extends Service {
await this.client?.scrollback(room);
}
}

async setLLMModelForCodeMode() {
this.setLLMModel('anthropic/claude-3.5-sonnet');
}

private async setLLMModel(model: string) {
if (!DEFAULT_LLM_LIST.includes(model)) {
throw new Error(`Cannot find LLM model: ${model}`);
}
if (!this.currentRoomId) {
return;
}
let roomResource = this.roomResources.get(this.currentRoomId);
if (!roomResource) {
return;
}
await roomResource.loading;
roomResource.activateLLM(model);
}
}

function saveAuth(auth: LoginResponse) {
Expand Down
6 changes: 6 additions & 0 deletions packages/host/app/services/operator-mode-state-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { type Stack } from '../components/operator-mode/interact-submode';

import { removeFileExtension } from '../components/search-sheet/utils';

import MatrixService from './matrix-service';
import NetworkService from './network';

import type CardService from './card-service';
Expand Down Expand Up @@ -97,6 +98,7 @@ export default class OperatorModeStateService extends Service {
@service private declare router: RouterService;
@service private declare reset: ResetService;
@service private declare network: NetworkService;
@service private declare matrixService: MatrixService;

constructor(owner: Owner) {
super(owner);
Expand Down Expand Up @@ -310,6 +312,10 @@ export default class OperatorModeStateService extends Service {
updateSubmode(submode: Submode) {
this.state.submode = submode;
this.schedulePersist();

if (submode === Submodes.Code) {
this.matrixService.setLLMModelForCodeMode();
}
}

updateCodePathWithCodeSelection(
Expand Down
27 changes: 26 additions & 1 deletion packages/host/tests/acceptance/ai-assistant-test.gts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { click, fillIn } from '@ember/test-helpers';
import { click, fillIn, waitFor } from '@ember/test-helpers';

import { module, test } from 'qunit';

Expand Down Expand Up @@ -326,4 +326,29 @@ module('Acceptance | AI Assistant tests', function (hooks) {
let roomState = getRoomState('mock_room_1', APP_BOXEL_ACTIVE_LLM, '');
assert.strictEqual(roomState.model, 'google/gemini-pro-1.5');
});

test('defaults to anthropic/claude-3.5-sonnet in code mode', async function (assert) {
await visitOperatorMode({
stacks: [
[
{
id: `${testRealmURL}index`,
format: 'isolated',
},
],
],
});

await click('[data-test-submode-switcher] button');
await click('[data-test-boxel-menu-item-text="Code"]');
await click('[data-test-open-ai-assistant]');
assert.dom('[data-test-llm-select-selected]').hasText('claude-3.5-sonnet');

createAndJoinRoom('@testuser:staging', 'room-test-2');

await click('[data-test-past-sessions-button]');
await waitFor("[data-test-enter-room='mock_room_2']");
await click('[data-test-enter-room="mock_room_2"]');
assert.dom('[data-test-llm-select-selected]').hasText('claude-3.5-sonnet');
});
});