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
20 changes: 20 additions & 0 deletions packages/host/app/components/matrix/room.gts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ import { AiAssistantConversation } from '../ai-assistant/message';
import NewSession from '../ai-assistant/new-session';
import AiAssistantSkillMenu from '../ai-assistant/skill-menu';

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

import RoomMessage from './room-message';

import type RoomData from '../../lib/matrix-classes/room';
Expand Down Expand Up @@ -239,6 +241,24 @@ export default class Room extends Component<Signature> {
registerDestructor(this, () => {
this.scrollState().messageVisibilityObserver.disconnect();
});

this.setRoomLLM();
Copy link
Contributor

@lukemelia lukemelia Jan 28, 2025

Choose a reason for hiding this comment

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

This looks like it running in the constructor of the room component. It seems like a surprising place to me that might miss certain cases. For example, creating a new room, or switching rooms?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My reasoning behind doing it this way is because I thought this made sense only for newly created rooms. But now I see it would be better to support switching rooms too, and move the logic out of the constructor. This is now fixed in later commits

}

private async setRoomLLM() {
let isCodeMode =
this.operatorModeStateService.state.submode === Submodes.Code;

if (isCodeMode) {
await this.roomResource.loading;
let llmModel = 'anthropic/claude-3.5-sonnet';
let foundModel = DEFAULT_LLM_LIST.includes(llmModel);
if (!foundModel) {
throw new Error(`Cannot find LLM model: ${llmModel}`);
}
await this.roomResource.loading;
this.roomResource.activateLLM(llmModel);
} // When in interactive mode, the default LLM is used
}

private scrollState() {
Expand Down
18 changes: 18 additions & 0 deletions packages/host/tests/acceptance/ai-assistant-test.gts
Original file line number Diff line number Diff line change
Expand Up @@ -326,4 +326,22 @@ 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 when 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');
});
});
Loading