Use vars inside a prompt
Transform and inject dynamic data into your prompts using variables. Variables allow you to process query results before using them in message content.
Generate from video subtitles using vars
Demonstrates using variables to process video subtitles. The code uses two JQ-formatted vars:
subtitles
: Extracts video subtitle entriescontext
: Creates a structure combining filename and transcription
The processed data is then injected into a message prompt using context
syntax, generating a summary of the video transcription. Results include generation metadata and usage statistics.
const {
data: { payload },
} = await unbody.get.videoFile
.select("subtitles.SubtitleFile.entries.SubtitleEntry.__typename")
.limit(1)
.generate.fromOne({
options: {
vars: [
{
name: "subtitles",
formatter: "jq",
expression: `(.subtitles//[]) | map({ entries })`,
},
{
name: "context",
formatter: "jq",
expression: `{
originalName,
transcription: $subtitles[0].entries
}`,
},
],
},
messages: [
{
content: `Summarize the video's transcription:
\`\`\`json
{context}
\`\`\`
`,
},
],
})
.exec();