0.1.13 • Published 5 months ago

openai-message-utils v0.1.13

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

openai-message-utils

A very simple Typescript library that makes OpenAI messages slightly easier to work with.

You probably don't need this library (or any library) to build prompts. JavaScript template literals are great for this!

This library helps with just two small annoyances.

trim

Allows you to indent prompts in your code for readability, while automatically trimming whitespace.

Just add the trim tagged template literal, and it will remove:

  • any leading or trailing whitespace from each line
  • any empty leading or trailing lines

Other empty lines will be preserved.

Usage:

const system = trim`
    You are a helpful assistant.
    This line looks indented in code, but the value won't be.
    The prompt starts/ends with empty lines, which will also be removed.
`

buildMessages

The buildMessages function handles the common case of creating a messages array from a single system message and/or user message (and trims them by default).

Usage:

const system = "You are a helpful assistant";
const user = `
    How do I say cheese in French?
`;
const messages = buildMessages({ system, user });

console.log(messages) =>
[
    { role: "system", content: "You are a helpful assistant" },
    { role: "user", content: "How do I say cheese in French?" },
]
0.1.13

5 months ago

0.1.3

5 months ago

0.1.2

5 months ago