Skip to content
English

ModelResult ​

CORE · type · 类型合同

Model call result with its model-call receipt.

导入 ​

ts
import type { ModelResult } from '@jangts/agent-core';
js
/** @typedef {import('@jangts/agent-core').ModelResult} ModelResult */

其他公开入口:@jangts/agent-core、@jangts/agent-core/types、@jangts/agent-core/structs。

定义 ​

类型: ModelResult<Value>

类型表达式
ts
type ModelResult<Value> = InvocationResult<Value, ModelCallRecord>;

泛型参数 ​

类型参数约束默认类型
Value——

字段结构 ​

字段类型必需说明
valueValue必需只读。见类型定义及调用场景。
invocationReadonly<ModelCallRecord>必需只读。见类型定义及调用场景。

使用示例 ​

同一输出的两种输入 ​

入门 · Node.js

ts
import { ModelRunner } from '@jangts/agent-core/model';
const provider = {
  async *stream(messages: readonly { content: string }[]) {
    yield '收到:' + messages.at(-1)!.content;
  },
};
const runner = new ModelRunner({ provider });
const first = await runner.invoke('你好');
const second = await runner.invoke({ input: '你好' });
console.log(first.value, second.value);
console.log(first.invocation.invocationId);
js
import { ModelRunner } from '@jangts/agent-core/model';
const provider = {
    async *stream(messages) {
        yield '收到:' + messages.at(-1).content;
    },
};
const runner = new ModelRunner({ provider });
const first = await runner.invoke('你好');
const second = await runner.invoke({ input: '你好' });
console.log(first.value, second.value);
console.log(first.invocation.invocationId);

增加预算与请求取消 ​

配置 · Node.js

ts
import { ModelRunner } from '@jangts/agent-core/model';
const provider = {
  async *stream(messages: readonly { content: string }[]) {
    yield '收到:' + messages.at(-1)!.content;
  },
};
const runner = new ModelRunner({ provider, maxCalls: 2, maxInputChars: 4000,
  maxOutputChars: 2000, callTimeoutMs: 15000,
  execution: { signal: AbortSignal.timeout(20000) },
});
const result = await runner.invoke({ input: '你好', stageId: 'reply', maxOutputTokens: 600 });
console.log(result.value, runner.remainingCalls);
js
import { ModelRunner } from '@jangts/agent-core/model';
const provider = {
    async *stream(messages) {
        yield '收到:' + messages.at(-1).content;
    },
};
const runner = new ModelRunner({ provider, maxCalls: 2, maxInputChars: 4000,
    maxOutputChars: 2000, callTimeoutMs: 15000,
    execution: { signal: AbortSignal.timeout(20000) },
});
const result = await runner.invoke({ input: '你好', stageId: 'reply', maxOutputTokens: 600 });
console.log(result.value, runner.remainingCalls);

相关策略源码 ​

相关定义 ​

接口参考、使用示例与开发指南。