You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You can use the chat API within your components to generate text using the configured LLMs. This is useful for creating dynamic content like stories, summaries, or finding information.
226
+
227
+
### Example: Generating a Story
228
+
229
+
The `XmasPage` component uses `ctx.chat.completion` to generate a Christmas story on mount.
story.value=`Santa is busy writing a christmas story...`
243
+
244
+
// 2. Create the request
245
+
constrequest=ctx.chat.createRequest({
246
+
model: availableStoryModel,
247
+
text:`Write a short, feel-good Christmas story set on a quiet winter evening. Focus on simple kindness, cozy details, and gentle magic—twinkling lights, warm drinks, falling snow, and a small act of generosity that brings people together. Keep the tone hopeful and comforting, with a soft, joyful ending that leaves the reader smiling.`,
248
+
systemPrompt: santaSystemPrompt,
249
+
})
250
+
251
+
// 3. Execute completion
252
+
constapi=awaitctx.chat.completion({
253
+
request
254
+
})
255
+
256
+
// 4. Handle response
257
+
if (api.response) {
258
+
story.value=ctx.chat.getAnswer(api.response)
259
+
} elseif (api.error) {
260
+
story.value=api.error.message
261
+
}
262
+
})
263
+
```
264
+
222
265
## Full Example Component: Top Panel
223
266
224
267
This is how you define a complex UI component like a Top Panel. It's just a standard Vue 3 component.
0 commit comments