Typescript Prompt file

Using typescript to define the prompt allows to type the arguments and benefit from autocomplete for the model name.

We define a prompt with definePrompt():

import { ai } from "../utils/ai"
import { gpt41 } from "genkitx-openai"
import { z } from "zod"

export const requestExamples = ai.definePrompt({
    name: "requestExamples",
    model: gpt41.name,
    input: {
        schema: z.object({
            character: z.string(),
        }),
    },
    prompt: `Make 3 example sentences for the character {{character}}.
  Provide the english translation but not the pinyin. Do not comment`,
})

call the prompt

call the prompt and wait for the full response

const { text } = await requestExamples({ character: "菠萝" })

call the prompt and stream the response

const { stream, response } = requestExamples.stream({ character: "菠萝" })

    for await (const chunk of stream) {
        ...
    }
earlymorning logo

© 2025 - All rights reserved

Typescript Prompt file

Using typescript to define the prompt allows to type the arguments and benefit from autocomplete for the model name.

We define a prompt with definePrompt():

import { ai } from "../utils/ai"
import { gpt41 } from "genkitx-openai"
import { z } from "zod"

export const requestExamples = ai.definePrompt({
    name: "requestExamples",
    model: gpt41.name,
    input: {
        schema: z.object({
            character: z.string(),
        }),
    },
    prompt: `Make 3 example sentences for the character {{character}}.
  Provide the english translation but not the pinyin. Do not comment`,
})

call the prompt

call the prompt and wait for the full response

const { text } = await requestExamples({ character: "菠萝" })

call the prompt and stream the response

const { stream, response } = requestExamples.stream({ character: "菠萝" })

    for await (const chunk of stream) {
        ...
    }