Who can use this feature: Anyone on any plan.

This feature is currently in beta. While you’re welcome to try it out, please know that our team is still working to refine it. Your feedback is valuable to help us improve!

Introduction

Helicone’s prompt management provides a seamless way for users to track the prompts used in their generative AI applications. With Helicone, you can effortlessly monitor versions and inputs as they evolve.

Example: A Prompt Template designed for a rap battle between two people.

Why Prompts

Requests are now matched to a helicone-prompt-id, allowing you to:

  • version and track iterations to your prompt over time, without losing any previous versions.
  • maintain a dataset of inputs and outputs for each prompt version.

Prerequisites

To use Prompts, you must set up Helicone in proxy mode via Gateway or custom package.

Not sure if proxy is for you? We created a guide to explain the difference between Helicone Proxy vs Helicone Async integration.

How Prompt Template Works

As you modify your prompt in code, Helicone automatically tracks the new version and maintains a record of the old prompt. Additionally, a dataset of input/output keys is preserved for each version.

Example

Let’s say we have an app that generates a short story, where users are able to input their own character. For example, the prompt is “Write a story about a secret agent”, where the character is “a secret agent”.

1

Import hprompt

import { hprompt } from "@helicone/helicone";
2

Add `hprompt` and identify input variables

Using the backtick string formatter in JavaScript, add hprompt in front of your backtick to automatically format your text so that Helicone can determine where your variables are.

Next, nest your inputted variable so that it is within another bracket {}, this is essentially making it so that we can determine the input key for Helicone.

content: hprompt`Write a story about ${{ character }}`,
3

Assign an id to your prompt

Assign a Helicone-Prompt-Id header to your LLM request.

Assigning an id allows us to associate your prompt with future versions of your prompt, and automatically manage versions on your behalf.

Depending on the package you are using, you will need to add a header. For more information on adding headers to packages, please see Header Directory.

headers: {
  "Helicone-Prompt-Id": "prompt_story",
},

Here’s what your code would look like:

// 1. Add this line
import { hprompt } from "@helicone/helicone";

const chatCompletion = await openai.chat.completions.create(
  {
    messages: [
      {
        role: "user",
        // 2: Add hprompt to any string, and nest any variable in additional brackets `{}`
        content: hprompt`Write a story about ${{ character }}`,
      },
    ],
    model: "gpt-3.5-turbo",
  },
  {
    // 3. Add Prompt Id Header
    headers: {
      "Helicone-Prompt-Id": "prompt_story",
    },
  }
);

Local Testing

Many times in development, you may want to test your prompt locally before deploying it to production and you don’t want Helicone to track new prompt versions.

To do this, you can set the Helicone-Prompt-Mode header to testing in your LLM request. This will prevent Helicone from tracking new prompt versions.

headers: {
  "Helicone-Prompt-Mode": "testing",
},