UNPKG

llama-flow

Version:

The Typescript-first prompt engineering toolkit for working with chat based LLMs.

37 lines (36 loc) 1.8 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const lodash_1 = require("lodash"); const zod_1 = require("zod"); const json_1 = __importDefault(require("./json")); function buildRawPrompt(prompt) { const arraySchema = zod_1.z.array(prompt.length ? zod_1.z .string() .max(prompt.length, `Each bullet point should be less than ${prompt.length} characters, including white spaces.`) : zod_1.z.string()); const formatMessages = (0, lodash_1.compact)([ "Respond to the prompt below in bullet points, where each bullet point starts with the - character. Don't include any other text other than the bullet points.", prompt.length ? `Each bullet point should be less than ${prompt.length} characters long, including white spaces.` : undefined, prompt.amount ? `There should be exactly ${prompt.amount} bullet points, no more or less.` : undefined, ]); return (0, json_1.default)({ message: `${formatMessages.join(' ')}\n\n${prompt.message}`, parseResponse: (res) => res .split('\n') .filter((s) => s.includes('-')) .map((s) => s.replace('-', '').trim()), schema: prompt.amount ? arraySchema.length(prompt.amount, `There should be exactly ${prompt.amount} bullet points, no more or less.`) : arraySchema, retryMessage: "Respond to the prompt above in bullet points, where each bullet point starts with the - character. Don't include any other text other than the bullet points.", }); } exports.default = buildRawPrompt;