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 🙏

© 2024 – Pkg Stats / Ryan Hefner

prompt-wrangler

v0.7.0

Published

A package for running prompts via Prompt Wrangler from a node environment.

Downloads

12

Readme

Prompt Wrangler

Prompt Wrangler is an app that makes it easy to manage GPT in production applications. This is a wrapper library around the Prompt Wrangler API.

Installation

You can install the package using npm:

npm install prompt-wrangler

Usage

To use the package, you need to create an instance of the PromptWrangler class.

const { PromptWrangler } = require("prompt-wrangler");

const pw = new PromptWrangler();

Once you have an instance of the PromptWrangler class, you can use it to create a prompt and run it with the desired arguments:

const prompt = pw.prompt("my_workspace/my_prompt");
const args = {
  name: "John",
};

const res = await prompt.run(args);
console.log(res.prediction);

Schemas

You can optionally pass in an arg Zod schema and an output Zod schema to get a strongly typed run function as well as run time validation.

Argument Schema

The argument schema needs to match the schema specified on the Prompt. You can optionally pass in a schema when creating the prompt.

import { z } from "zod";

// Schema for the arguments
const argSchema = z.object({
  name: z.string(),
});

const prompt = promptWrangler.prompt("my_workspace/my_prompt", {
  argSchema: argSchema,
});

Output Schema

The output schema needs to match the output format and structure defined in the prompt. Generally, an output schema is used when the format is JSON and a specific schema is passed into the prompt. This will validate that the schema matches what you expect.

import { z } from "zod";

// Schema for the output
const outputSchema = z.object({
  key: z.string(),
});

const prompt = promptWrangler.prompt("my_workspace/my_prompt", {
  outputSchema: outputSchema,
});

const res = await prompt.run(args);

// Prediction is guaranteed to match the output schema and strongly typed
const prediction = res.prediction;

API Reference

PromptWrangler

The PromptWrangler class is the main class for interacting with the Prompt Wrangler API. It encapsulates all HTTP communication with the API.

constructor(base_url?: string)

Creates a new instance of the PromptWrangler class.

  • base_url - Optional. The base URL for the Prompt Wrangler API. Defaults to "https://prompt-wrangler.com/api".

prompt(prompt_path: string, options?: PromptWranglerPromptOptions)

This function creates a prompt that can be executed. The prompt_path parameter should be the workspace_slug/prompt_slug. This can be copied from the Prompt Wrangler UI.

  • prompt_path - The path to the prompt in the format workspace_slug/prompt_slug. For example, my_workspace/my_prompt.
  • options - Optional. An object with optional argSchema and outputSchema properties.

Returns an instance of PromptWranglerPrompt configured with the given prompt path and options.

PromptWranglerPrompt

The PromptWranglerPrompt class manages individual prompts hosted on the Prompt Wrangler API.