prompt-merge
TypeScript icon, indicating that this package has built-in type declarations

1.0.9 • Public • Published
banner for prompt merge

prompt-merge

NPM Version Code Standards & Testing Checked with Biome

Zero-dependency library for conditionally merging LLM (system) prompts into a single string.

Installation

npm install prompt-merge

Usage

import pm from "prompt-merge";
import { generateText } from "ai";

const result = await generateText({
  model: openai("gpt-4o"),
  system: pm(
    "You are a helpful assistant.",
    canTranslate && "You can translate text.",
    {
      "You support translating Japanese to English": canTranslateJapanese,
      "You support translating German to English": canTranslateGerman,
    }
  ),
  messages,
});

Acknowledgements

This package was inspired by two packages I've used for managing classNames (which for all intents and purposes is what prompts are... just strings):




Sponsorship
Special thanks to:


/prompt-merge/

    Package Sidebar

    Install

    npm i prompt-merge

    Weekly Downloads

    3

    Version

    1.0.9

    License

    MIT

    Unpacked Size

    20.6 kB

    Total Files

    9

    Last publish

    Collaborators

    • zrosenbauer