npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@completionhq/promptfactory-node

v0.0.3

Published

The PromptFactory Node SDK is a fast and lightweight to create and manage prompts for your LLM application.

Downloads

2,588

Readme

PromptFactory Library

The PromptFactory library provides a robust, efficient, and language-independent solution for constructing and managing prompt templates for use with various AI models, including but not limited to LLMs (Large Language Models) and text-to-image models. It bridges the gap between complex project structures like LangChain and straightforward string templating approaches, offering a streamlined and developer-friendly toolset for prompt management.

Key Objectives

  • Efficiency and Simplicity: Offer a rapid and straightforward interface for prompt management within software projects, without the need for extensive dependencies.
  • Model Compatibility: Ensure compatibility with a wide range of AI models, including OpenAI, Mistral, Llama, etc., facilitating easy integration and flexibility in usage.
  • Developer-Focused: Design with a focus on developer needs, allowing for prompt customization, argument validation, and easy storage and versioning of prompt templates within code repositories.

Features

  • Ease of Use: Intuitive API for prompt creation and management, supporting both simple and complex prompt configurations.
  • Argument Validation: Built-in support for validating and hydrating prompt arguments, ensuring dynamic prompts are generated accurately.
  • Model Agnostic: Works seamlessly with any AI model accepting text or structured message prompts.
  • Versatile Prompt Management: Allows for the storage of prompt templates and arguments in code, simplifying version control and collaboration.

Installation

Install the PromptFactory library using npm or yarn:

npm install @completionhq/promptfactory-node

# or

yarn add @completionhq/promptfactory-node

Usage

Below are examples demonstrating how to use PromptFactory for creating and utilizing prompts.

Basic Prompt Creation

// Import required classes and types
import { StringPrompt, MessageArrayPrompt } from '@completionhq/promptfactory-node'; // Assuming the classes are exported from 'promptClasses.js'

// Create a StringPrompt instance
const stringPrompt = new StringPrompt("ExamplePrompt", {
  template: "Hello, {{name}}! How can I assist you today?",
  promptArguments: { name: "John Doe" },
});

// Or set the template and arguments separately
stringPrompt.setTemplate("Hello, {{name}}! How can I assist you today?");
stringPrompt.setArguments({ name: "John Doe" });

// Hydrate the string template to produce the final prompt
const hydratedStringPrompt = stringPrompt.hydrate();
console.log(hydratedStringPrompt); // Output: Hello, John Doe! How can I assist you today?

Basic Message Array Prompt Creation (OpenAI / Chat Completion format)

// Create a MessageArrayPrompt instance
const messageArrayPrompt = new MessageArrayPrompt("ExamplePrompt", {
  template: [
    {
      role: "system",
      content: "Hello, {{name}}! How can I assist you today?",
    }
  ],
  promptArguments: { name: "John Doe" },
});

// Or set the template and arguments separately
messageArrayPrompt.setTemplate([
  {
    role: "system",
    content: "Hello, {{name}}! How can I assist you today?",
  }
]);
messageArrayPrompt.setArguments({ name: "John Doe" });

// Hydrate the message array template to produce the final array of messages
const hydratedMessages = messageArrayPrompt.hydrate();
console.log(hydratedMessages); // Output: [{ role: 'system', content: 'Hello, John Doe! How can I assist you today?' }]

// For serialization and deserialization, refer to the utilities provided in the new interfaces

Integration with OpenAI

import { OpenAI } from 'openai-node';

const prompt = new MessageArrayPromptFactory("OpenAIPrompt", {
  messagesTemplate: [
    { role: "system", content: "Hello, {{name}}! How can I assist you today?" }
  ],
  promptArguments: { name: "John Doe" },
});

const openai = new OpenAI({
  apiKey: config.openaiApiKey,
});
const result = await openai.chat.completions.create({
  model: 'gpt-3.5-turbo',
  messages: prompt.getHydratedMessagesArray(),
});

console.log(result.choices[0].message.content);

Configuration Options

Customize the behavior of PromptFactory with various configuration options:

  • promptTemplate: String template for generating simple text prompts.
  • messagesTemplate: Array of chat completion parameters for creating structured message prompts.
  • promptArguments: Object containing variables to be interpolated into the prompt or messages template.
  • parser: Specifies the template parser to use, defaulting to FString for simple string interpolation.
  • fileSerializationFormat: Determines the format used for loading and saving prompts from/to files, with JSON as the default format.

Advanced Features

  • File-based Prompt Management: Load and manage prompts directly from files, supporting both JSON and YAML formats for ease of use and version control.
  • Dynamic Argument Hydration: Seamlessly interpolate dynamic variables into prompts, ensuring accurate and contextually relevant prompt generation.
  • Comprehensive Validation: Utilize built-in validation mechanisms to ensure prompt templates and arguments are correctly formatted and error-free.