TextTemplateOptions
KIT · interface · 类型合同
Text template construction options.
导入
ts
import type { TextTemplateOptions } from '@jangts/agent-core/kits/presentation';1
js
/** @typedef {import('@jangts/agent-core/kits/presentation').TextTemplateOptions} TextTemplateOptions */1
其他公开入口:@jangts/agent-core、@jangts/agent-core/types、@jangts/agent-core/structs、@jangts/agent-core/kits/presentation、@jangts/agent-core/kits。
定义
ts
interface TextTemplateOptions1
字段结构
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
observe | ((result: string) => void | Promise<void>) | undefined | 可省略 | 只读。Observer invoked with every rendered text. |
errors | { readonly missingField?: (key: string) => Error | string; } | undefined | 可省略 | 只读。Builds the error for a slot the caller did not supply; receives the slot name. |
使用示例
- Presentation:字段所有权与最终输出:模型只填写被分配的字段;固定文字、绑定值和语义键由程序拥有。
- 模板、语义槽与表达选择:程序拥有模板和偏好顺序,插入值只替换一次,变体随机源由 App 提供。
先组合一段生成文本
入门 · Node.js
ts
import { Presentation } from '@jangts/agent-core/kits/presentation';
const outputs = Presentation.defineOutputCatalog([
{ id: 'reply', kind: 'text', fields: [{ id: 'text', owner: 'generated' }] },
]);
console.log(outputs.toModelSchema('reply'));
const output = outputs.compose({ outputId: 'reply', input: { generated: { text: '普通对象即可定义节点。' } } }, { app: {}, signal: new AbortController().signal });
console.log(output.value);1
2
3
4
5
6
7
2
3
4
5
6
7
js
import { Presentation } from '@jangts/agent-core/kits/presentation';
const outputs = Presentation.defineOutputCatalog([
{ id: 'reply', kind: 'text', fields: [{ id: 'text', owner: 'generated' }] },
]);
console.log(outputs.toModelSchema('reply'));
const output = outputs.compose({ outputId: 'reply', input: { generated: { text: '普通对象即可定义节点。' } } }, { app: {}, signal: new AbortController().signal });
console.log(output.value);1
2
3
4
5
6
7
2
3
4
5
6
7
相同 compose 让程序持有说明前缀
配置 · Node.js
ts
import { Presentation } from '@jangts/agent-core/kits/presentation';
const outputs = Presentation.defineOutputCatalog([
{ id: 'reply', kind: 'master', master: '{{prefix}}{{text}}', fields: [
{ id: 'prefix', owner: 'constant', constantValue: '接口说明:' },
{ id: 'text', owner: 'generated' },
] },
]);
console.log(outputs.toModelSchema('reply')); // 只有 text 由模型填写
console.log(outputs.compose({ outputId: 'reply', input: { generated: { text: '普通对象即可定义节点。' } } }, { app: {}, signal: new AbortController().signal }).value);1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
js
import { Presentation } from '@jangts/agent-core/kits/presentation';
const outputs = Presentation.defineOutputCatalog([
{ id: 'reply', kind: 'master', master: '{{prefix}}{{text}}', fields: [
{ id: 'prefix', owner: 'constant', constantValue: '接口说明:' },
{ id: 'text', owner: 'generated' },
] },
]);
console.log(outputs.toModelSchema('reply')); // 只有 text 由模型填写
console.log(outputs.compose({ outputId: 'reply', input: { generated: { text: '普通对象即可定义节点。' } } }, { app: {}, signal: new AbortController().signal }).value);1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9