Typescript Prompt file

Using typescript to define the prompt brings type safety and autocomplete, notably when the prompt makes use of arguments.

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`,
})

stream the response

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

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

await the response

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

© 2025 - All rights reserved

Typescript Prompt file

Using typescript to define the prompt brings type safety and autocomplete, notably when the prompt makes use of arguments.

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`,
})

stream the response

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

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

await the response

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