Show typed results as they arrive
You can render typed deltas while the answer is still arriving. The final result remains governed by the same signature and assertions.
Worked example
See the idea in context
for await (const chunk of program.streamingForward(llm, input)) { if (chunk.delta.answer) render(chunk.delta.answer); }- Open a typed stream
streamingForward() uses the same provider, input, and contract as forward().
- Read only present fields
A chunk may contain an answer delta while other fields are still incomplete.
- Render without reparsing
The UI consumes signature-aware deltas instead of scraping provider text.
Run itIn your own project
npm install @ax-llm/ax
import { ai, ax } from '@ax-llm/ax';
const llm = ai({ name: 'openai', apiKey: process.env.OPENAI_APIKEY! });
const classify = ax('review:string -> sentiment:class "positive, negative, neutral"');
const result = await classify.forward(llm, {
review: 'Useful and boring in the best way.',
});Set OPENAI_APIKEY in your environment before running provider-backed code.
From a clone of the ax repo:
npm run example -- typescript src/examples/typescript/generation/axgen-openai.tsActive practice
Answer 2 in a row to learn this · attempt 1