-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathset-llm-example.gts
210 lines (178 loc) · 5 KB
/
set-llm-example.gts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
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<typeof SetLlmExample> {
@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;
}
<template>
<div class='llm-setter'>
<div class='content'>
<div class='input-section'>
<label for='llm-model-name-input'>LLM Model Name</label>
<input
type='text'
value={{this.modelId}}
{{on 'input' this.updatemodelId}}
class='model-input'
id='llm-model-name-input'
/>
</div>
<div class='buttons-section'>
<Button
class='create-button'
data-test-create-room
{{on 'click' this.createRoom}}
>
Create Room
</Button>
<Button
class='set-button'
data-test-set-llm
{{on 'click' this.setLLM}}
>
Set Active LLM
</Button>
</div>
{{#if this.currentRoomId}}
<div class='room-info'>
<span class='room-label'>Room ID:</span>
<span class='room-id'>{{this.currentRoomId}}</span>
</div>
{{/if}}
</div>
</div>
<style scoped>
.llm-setter {
max-width: 600px;
margin: 0 auto;
padding: 2rem;
}
.content {
background: white;
border-radius: 16px;
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
padding: 1.5rem;
}
.input-section {
margin-bottom: 1.5rem;
}
.input-section label {
display: block;
margin-bottom: 0.5rem;
color: #7f8c8d;
font-size: 0.9rem;
}
.model-input {
width: 100%;
padding: 0.75rem;
border: 1px solid #e2e8f0;
border-radius: 8px;
font-size: 1rem;
transition: border-color 0.2s;
}
.model-input:focus {
outline: none;
border-color: #34d399;
box-shadow: 0 0 0 3px rgba(52, 211, 153, 0.2);
}
.buttons-section {
display: flex;
gap: 1rem;
margin-bottom: 1rem;
}
.create-button,
.set-button {
flex: 1;
padding: 0.75rem 1.5rem;
font-size: 1.1rem;
color: white;
border: none;
border-radius: 8px;
cursor: pointer;
transition:
transform 0.2s,
box-shadow 0.2s;
}
.create-button {
background: linear-gradient(135deg, #4f46e5, #3730a3);
}
.set-button {
background: linear-gradient(135deg, #34d399, #059669);
}
.create-button:hover,
.set-button:hover {
transform: translateY(-1px);
}
.create-button:hover {
box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
}
.set-button:hover {
box-shadow: 0 4px 12px rgba(52, 211, 153, 0.3);
}
.set-button[disabled] {
opacity: 0.5;
cursor: not-allowed;
transform: none;
box-shadow: none;
}
.room-info {
margin-top: 1rem;
padding: 1rem;
background: #f8fafc;
border-radius: 8px;
font-size: 0.9rem;
}
.room-label {
color: #64748b;
margin-right: 0.5rem;
}
.room-id {
color: #1e293b;
font-family: monospace;
font-size: 0.95rem;
}
</style>
</template>
}
export class SetLlmExample extends CardDef {
static displayName = 'SetLLMExample';
static isolated = IsolatedTemplate;
}