Reintent
/

generate

An open choice whose candidates System Two writes.

function generate<T>(instruction, opts?): Generation<T>;

Defined in: packages/core/src/intent/hooks.ts

Describe an open choice whose candidates System Two writes. Reading it with useChoose sends the request when the evaluation is shown. n is a positive integer, default 1. For n = 1 the model returns one value; for n > 1 it returns an array of n values. Candidates have equal weights; wrap in judge to ask System One to weigh them. check filters each candidate; duplicate tags keep the first valid value. The generated layer caches answers by identity, instruction, n, uses and facts. A person's decision or preview may supply another value of T, subject to check.

Type Parameters

Type Parameter
T

Parameters

ParameterType
instructionstring
opts{ check?: (value) => string[]; n?: number; uses?: Record<string, unknown>; }
opts.check?(value) => string[]
opts.n?number
opts.uses?Record<string, unknown>

Returns

Generation<T>

Example

import { createIntent, generate, host, useChoose } from '@reintent/core';
function Greeting() {
  const line = useChoose(generate<string>('A greeting for Ann', { n: 3 }), {
    of: 'card',
    name: 'line',
    defaultValue: '…',
  });
  return host('text', { line });
}
const intent = createIntent({
  program: <Greeting />,
  model: { generate: () => ['Hello Ann', 'Welcome Ann', 'Hi Ann'] },
});
const connection = intent.connect({ commit() {} });
console.log(intent.realize().reads[0].kinds.length); // → 3
intent.decide({ of: 'card', name: 'line' }, 'My own greeting');
console.log(intent.realize().reads[0].value); // → 'My own greeting'
connection.disconnect();

Last updated on

Edit on GitHub