Skip to content

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

License

Notifications You must be signed in to change notification settings

zrosenbauer/prompt-merge

Repository files navigation

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:


About

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

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Sponsor this project