diff --git a/packages/base/command.gts b/packages/base/command.gts index e9d0f2d17c..162b0aac7e 100644 --- a/packages/base/command.gts +++ b/packages/base/command.gts @@ -70,6 +70,11 @@ export class CreateAIAssistantRoomResult extends CardDef { @field roomId = contains(StringField); } +export class SetActiveLLMInput extends CardDef { + @field roomId = contains(StringField); + @field model = contains(StringField); +} + export class AddSkillsToRoomInput extends CardDef { @field roomId = contains(StringField); @field skills = linksToMany(SkillCard); diff --git a/packages/experiments-realm/set-llm-example.gts b/packages/experiments-realm/set-llm-example.gts new file mode 100644 index 0000000000..3ca2f43506 --- /dev/null +++ b/packages/experiments-realm/set-llm-example.gts @@ -0,0 +1,210 @@ +import { CardDef, Component } from 'https://cardstack.com/base/card-api'; +import { tracked } from '@glimmer/tracking'; +import { action } from '@ember/object'; +import { on } from '@ember/modifier'; +import SetActiveLLMCommand from '@cardstack/boxel-host/commands/set-active-llm'; +import CreateAiAssistantRoomCommand from '@cardstack/boxel-host/commands/create-ai-assistant-room'; +import OpenAiAssistantRoomCommand from '@cardstack/boxel-host/commands/open-ai-assistant-room'; +import { Button } from '@cardstack/boxel-ui/components'; + +class IsolatedTemplate extends Component { + @tracked modelId = 'microsoft/phi-4'; + @tracked currentRoomId: string | null = null; + + @action + async createRoom() { + let commandContext = this.args.context?.commandContext; + if (!commandContext) return; + + let createAIAssistantRoomCommand = new CreateAiAssistantRoomCommand( + commandContext, + ); + let { roomId } = await createAIAssistantRoomCommand.execute({ + name: `Chat with ${this.modelId}`, + }); + + let openAiAssistantRoomCommand = new OpenAiAssistantRoomCommand( + commandContext, + ); + await openAiAssistantRoomCommand.execute({ + roomId, + }); + + this.currentRoomId = roomId; + } + + @action + async setLLM() { + if (!this.currentRoomId) return; + + let commandContext = this.args.context?.commandContext; + if (!commandContext) return; + + let setActiveLLMCommand = new SetActiveLLMCommand(commandContext); + + await setActiveLLMCommand.execute({ + model: this.modelId, + roomId: this.currentRoomId, + }); + } + + @action + updatemodelId(event: Event) { + this.modelId = (event.target as HTMLInputElement).value; + } + + +} + +export class SetLlmExample extends CardDef { + static displayName = 'SetLLMExample'; + + static isolated = IsolatedTemplate; +} diff --git a/packages/host/app/commands/index.ts b/packages/host/app/commands/index.ts index 54006dce6f..b4ecb331f6 100644 --- a/packages/host/app/commands/index.ts +++ b/packages/host/app/commands/index.ts @@ -9,6 +9,7 @@ import * as ReloadCardCommandModule from './reload-card'; import * as SaveCardCommandModule from './save-card'; import * as SearchCardsCommandModule from './search-cards'; import * as SendAiAssistantMessageModule from './send-ai-assistant-message'; +import * as SetActiveLlmModule from './set-active-llm'; import * as ShowCardCommandModule from './show-card'; import * as SwitchSubmodeCommandModule from './switch-submode'; import * as UpdateSkillActivationCommandModule from './update-skill-activation'; @@ -51,6 +52,10 @@ export function shimHostCommands(virtualNetwork: VirtualNetwork) { '@cardstack/boxel-host/commands/send-ai-assistant-message', SendAiAssistantMessageModule, ); + virtualNetwork.shimModule( + '@cardstack/boxel-host/commands/set-active-llm', + SetActiveLlmModule, + ); virtualNetwork.shimModule( '@cardstack/boxel-host/commands/show-card', ShowCardCommandModule, diff --git a/packages/host/app/commands/set-active-llm.ts b/packages/host/app/commands/set-active-llm.ts new file mode 100644 index 0000000000..dbd1e00fbd --- /dev/null +++ b/packages/host/app/commands/set-active-llm.ts @@ -0,0 +1,27 @@ +import { service } from '@ember/service'; + +import type * as BaseCommandModule from 'https://cardstack.com/base/command'; + +import HostBaseCommand from '../lib/host-base-command'; + +import type MatrixService from '../services/matrix-service'; + +export default class SetActiveLLMCommand extends HostBaseCommand< + typeof BaseCommandModule.SetActiveLLMInput, + undefined +> { + @service private declare matrixService: MatrixService; + + async getInputType() { + let commandModule = await this.loadCommandModule(); + const { SetActiveLLMInput } = commandModule; + return SetActiveLLMInput; + } + + protected async run( + input: BaseCommandModule.SetActiveLLMInput, + ): Promise { + await this.matrixService.sendActiveLLMEvent(input.roomId, input.model); + return undefined; + } +}