Giao diện sinh tạo với Lyra Gen

Câu trả lời của mô hình hiển thị thành các điều khiển Lyra thật, đã được xác thực.

Lyra Gen biến câu trả lời có cấu trúc của mô hình thành các thành phần Lyra dễ truy cập thông qua một danh mục đã được rà soát. Nội dung được sinh ra chỉ có thể nêu các vai trò trong danh mục, không bao giờ là thẻ, tập lệnh hay hành động tùy ý; ứng dụng của bạn giữ yêu cầu gửi mô hình, dữ liệu, hành động và lưu trữ.

Ví dụ

Chọn một tập con danh mục đã rà soát, rồi xác thực khung nhìn được sinh ra trước khi hiển thị.

import '@aceshooting/lyra-ui/theme.css';
import { initialCatalog, subsetCatalog } from '@aceshooting/lyra-gen/catalog.js';
import { validateView } from '@aceshooting/lyra-gen/runtime.js';
import { LyraGenViewElement } from '@aceshooting/lyra-gen/gen-view.js';

const selected = subsetCatalog(initialCatalog, ['stack', 'heading', 'text']);
if (!selected.ok) throw new Error('The requested catalog is unavailable.');
const catalog = selected.value;
const result = validateView({
  version: '1', catalog: { id: catalog.id, version: catalog.version },
  surfaceId: 'answer-1', revision: 0,
  root: { id: 'summary', type: 'stack', children: [
    { id: 'title', type: 'heading', text: 'Quarterly summary' },
    { id: 'detail', type: 'text', text: 'Revenue increased this quarter.' },
  ] },
}, catalog);
if (!result.ok) throw new Error('The generated view was rejected.');

const view = new LyraGenViewElement();
view.catalog = catalog;
view.document = result.value;
document.body.append(view);

Duyệt các thành phần · Đọc hướng dẫn (tiếng Anh)