Skip to main content

Enrich with AI

This guide shows how to use the OpenAI Transformer node to apply LLM prompts to each record in a stream, adding AI-generated fields to your data.

Prerequisites

  • TypeStream installed and running
  • An OpenAI API key set as the OPENAI_API_KEY environment variable on the server

Apply an LLM prompt

The OpenAI Transformer node sends a prompt (which can reference record fields) to an OpenAI model and stores the response in a new output field.

{
"name": "wikipedia-with-summary",
"version": "1",
"description": "Generate AI summaries for Wikipedia changes",
"graph": {
"nodes": [
{
"id": "source-1",
"kafkaSource": {
"topicPath": "/dev/kafka/local/topics/wikipedia_changes",
"encoding": "AVRO"
}
},
{
"id": "ai-1",
"openAiTransformer": {
"prompt": "Write a one-sentence summary of this Wikipedia edit to the article: ${title}",
"outputField": "ai_summary",
"model": "gpt-4o-mini"
}
},
{
"id": "sink-1",
"kafkaSink": {
"topicName": "wikipedia_with_summaries"
}
}
],
"edges": [
{ "fromId": "source-1", "toId": "ai-1" },
{ "fromId": "ai-1", "toId": "sink-1" }
]
}
}

Configuration

FieldDescription
promptThe prompt template sent to the model. Reference record fields with ${fieldName}.
outputFieldName of the new field added to each record with the model's response.
modelOpenAI model name (e.g. gpt-4o-mini, gpt-4o).

Schema behavior

The OpenAI Transformer adds outputField (type: string) to the output schema. Downstream nodes can reference this field for further processing -- for example, generating embeddings from the AI summary.

See also