Complete example demonstrating agent streaming with TOON format using @programsmagic/toon-backend-node and @programsmagic/toon-frontend.
This example shows how to:
cd examples/agent-streaming
pnpm install
pnpm start
The server will start on http://localhost:3000.
# Stream TOON format
curl "http://localhost:3000/stream/toon?file=data.json&format=json&model=gpt-4"
# Stream with format conversion
curl "http://localhost:3000/stream/toon?file=data.json&from=json&to=toon"
GET /stream/toon?file=data.json - Stream data in TOON formatGET /events - SSE event streamPOST /convert - Convert between formatsPOST /tokens - Count tokens for dataPOST /optimize - Optimize data for LLMimport { createServer } from '@programsmagic/toon-backend-node';
const server = await createServer({
port: 3000,
schemaSource: './schema.json',
cors: true,
});
await server.start();
console.log('Server running at http://localhost:3000');
import { StreamViewer } from '@programsmagic/toon-frontend';
import '@programsmagic/toon-frontend/styles';
function App() {
return (
<StreamViewer
url="http://localhost:3000/stream/toon?file=data.json"
protocol="sse"
showTokenCounter={true}
model="gpt-4"
/>
);
}
When you access the streaming endpoint, you’ll see:
data: {"type":"STREAM_START","timestamp":1234567890}
data: {"type":"TOKEN_COUNT","tokens":150,"model":"gpt-4"}
data: {"type":"FORMAT_CONVERTED","from":"json","to":"toon"}
data: {"type":"STREAM_END","timestamp":1234567891}
Problem: No data streaming from endpoint.
Solution:
curl http://localhost:3000/healthls data.jsonProblem: Token counting fails.
Solution:
gpt-4, gpt-3.5-turbo, claude-3-opus, etc.Problem: Format conversion fails.
Solution:
json, toon, csv, or yaml