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 formatworkspace_slug/prompt_slug
. For example,my_workspace/my_prompt
.options
- Optional. An object with optionalargSchema
andoutputSchema
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.