Skip to content

Commit

Permalink
Set LLM on host side (#2109)
Browse files Browse the repository at this point in the history
  • Loading branch information
FadhlanR authored Jan 31, 2025
1 parent 005b910 commit 50177c8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 22 deletions.
9 changes: 0 additions & 9 deletions packages/ai-bot/lib/matrix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,6 @@ export async function sendEvent(
return await client.sendEvent(roomId, eventType, content);
}

export async function updateStateEvent(
client: MatrixClient,
roomId: string,
eventType: string,
content: IContent,
) {
return await client.sendStateEvent(roomId, eventType, content, '');
}

export async function sendMessage(
client: MatrixClient,
roomId: string,
Expand Down
15 changes: 2 additions & 13 deletions packages/ai-bot/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ import {
extractCardFragmentsFromEvents,
eventRequiresResponse,
} from './helpers';
import {
APP_BOXEL_ACTIVE_LLM,
DEFAULT_LLM,
} from '@cardstack/runtime-common/matrix-constants';

import {
shouldSetRoomTitle,
Expand All @@ -28,7 +24,7 @@ import {
} from './lib/set-title';
import { Responder } from './lib/send-response';
import { handleDebugCommands } from './lib/debug';
import { MatrixClient, updateStateEvent } from './lib/matrix';
import { MatrixClient } from './lib/matrix';
import type { MatrixEvent as DiscreteMatrixEvent } from 'https://cardstack.com/base/matrix-event';
import * as Sentry from '@sentry/node';

Expand Down Expand Up @@ -125,12 +121,6 @@ class Assistant {
) {
return setTitle(this.openai, this.client, roomId, history, this.id, event);
}

async setDefaultLLM(roomId: string) {
await updateStateEvent(this.client, roomId, APP_BOXEL_ACTIVE_LLM, {
model: DEFAULT_LLM,
});
}
}

let startTime = Date.now();
Expand Down Expand Up @@ -171,9 +161,8 @@ Common issues are:
if (member.membership === 'invite' && member.userId === aiBotUserId) {
client
.joinRoom(member.roomId)
.then(async function () {
.then(function () {
log.info('%s auto-joined %s', member.name, member.roomId);
await assistant.setDefaultLLM(member.roomId);
})
.catch(function (err) {
log.info(
Expand Down
8 changes: 8 additions & 0 deletions packages/host/app/commands/create-ai-assistant-room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ import format from 'date-fns/format';

import { aiBotUsername } from '@cardstack/runtime-common';

import {
APP_BOXEL_ACTIVE_LLM,
DEFAULT_LLM,
} from '@cardstack/runtime-common/matrix-constants';

import type * as BaseCommandModule from 'https://cardstack.com/base/command';

import HostBaseCommand from '../lib/host-base-command';
Expand Down Expand Up @@ -51,6 +56,9 @@ export default class CreateAIAssistantRoomCommand extends HostBaseCommand<
aiBotFullId,
matrixService.aiBotPowerLevel,
);
await this.matrixService.sendStateEvent(roomId, APP_BOXEL_ACTIVE_LLM, {
model: DEFAULT_LLM,
});
let commandModule = await this.loadCommandModule();
const { CreateAIAssistantRoomResult } = commandModule;
return new CreateAIAssistantRoomResult({ roomId });
Expand Down

0 comments on commit 50177c8

Please sign in to comment.