GenerationInput
KIT · interface · Type contract
Input of MockGPT.generate.
Normalized exactly like an HTTP request body, so a rule matches identically through both entry points; only model and messages are required.
Import
ts
import type { GenerationInput } from '@jangts/agent-core/mock';js
/** @typedef {import('@jangts/agent-core/mock').GenerationInput} GenerationInput */Other public entry points:@jangts/agent-core/mock.
Definition
ts
interface GenerationInputField structure
| Field | Type | Required | Description |
|---|---|---|---|
model | string | Required | Read-only. Model identifier used for Rule.model filtering. |
messages | readonly Readonly<{ [key: string]: unknown; role: string; content?: unknown; tool_calls?: unknown; tool_call_id?: string; }>[] | Required | Read-only. Conversation whose last user message becomes the prompt. |
Index structure
| Field | Type | Required | Description |
|---|---|---|---|
[key: string] | unknown | Required | Read-only. Index entry. |
Examples
- MockGPT: direct generation and Provider injection: Get a string or JSON directly; inject the same instance into a Provider when you need to exercise model communication.
Generate native JSON directly
Beginner · Node.js
ts
import { MockGPT } from '@jangts/agent-core/mock';
const mock = new MockGPT({ rules: [{ prompt: '服务状态', generator: { online: true, source: 'fixture' } }] });
const value = await mock.generate({ model: 'demo', messages: [{ role: 'user', content: '服务状态' }] });
console.log(value); // { online: true, source: 'fixture' }
console.log(mock.counts, mock.records);js
import { MockGPT } from '@jangts/agent-core/mock';
const mock = new MockGPT({ rules: [{ prompt: '服务状态', generator: { online: true, source: 'fixture' } }] });
const value = await mock.generate({ model: 'demo', messages: [{ role: 'user', content: '服务状态' }] });
console.log(value); // { online: true, source: 'fixture' }
console.log(mock.counts, mock.records);Inject the same instance into the real Core model boundary
Configuration · Node.js
ts
import { ModelRunner, Support } from '@jangts/agent-core';
import { MockGPT, responses } from '@jangts/agent-core/mock';
const mock = new MockGPT({ rules: [{ prompt: '服务状态', generator: responses.text('服务在线。', { chunkSize: 2, wireChunkSize: 3 }) }] });
const provider = new Support.CompatibleModelProvider({
config: { baseUrl: 'https://mock.local/v1', apiKey: 'offline-example', model: 'demo' },
ports: { request: mock.fetch },
});
const result = await new ModelRunner({ provider, maxCalls: 1 }).invoke('服务状态');
console.log(result.value, result.invocation.status);js
import { ModelRunner, Support } from '@jangts/agent-core';
import { MockGPT, responses } from '@jangts/agent-core/mock';
const mock = new MockGPT({ rules: [{ prompt: '服务状态', generator: responses.text('服务在线。', { chunkSize: 2, wireChunkSize: 3 }) }] });
const provider = new Support.CompatibleModelProvider({
config: { baseUrl: 'https://mock.local/v1', apiKey: 'offline-example', model: 'demo' },
ports: { request: mock.fetch },
});
const result = await new ModelRunner({ provider, maxCalls: 1 }).invoke('服务状态');
console.log(result.value, result.invocation.status);