Primitives.org.ai

list

Generate a list of items

Generate a list of items. Supports streaming with async iteration.

Import

import { list } from 'ai-functions'

Syntax

list`prompt`
list`prompt`(options)
for await (const item of list`prompt`) { }

Examples

// Get all at once
const ideas = await list`startup ideas for ${industry}`
const tags = await list`tags for: ${articleContent}`

// With count
const topTen = await list`10 blog post titles for ${topic}`

// Stream items as generated
for await (const idea of list`startup ideas for ${industry}`) {
  console.log(idea)
}

Streaming Pattern

Process items as they're generated:

for await (const idea of list`startup ideas for ${industry}`) {
  const validation = await research`market size for ${idea}`

  if (validation.marketSize > 1_000_000_000) {
    console.log('Billion dollar idea:', idea)
    break  // Early termination
  }
}

Options

OptionTypeDescription
countnumberNumber of items to generate
modelstringModel to use

Use Cases

// Brainstorming
const features = await list`features for ${product}`
const angles = await list`marketing angles for ${campaign}`

// Content planning
const titles = await list`25 blog post titles for ${topic}`
const chapters = await list`chapters for book about ${subject}`

// Research
const questions = await list`research questions about ${topic}`
const keywords = await list`SEO keywords for ${page}`
Was this page helpful?

On this page