banana-prompts
v1767513.690.29
Published
Professional integration for https://bananaproai.com/banana-prompts/
Maintainers
Readme
banana-prompts
A JavaScript library to streamline prompt creation and management for AI models, enhancing your development workflow. It provides utility functions for constructing, validating, and formatting prompts.
Installation
bash npm install banana-prompts
Usage Examples
Here are a few examples demonstrating how to use banana-prompts in your JavaScript/Node.js applications:
1. Simple Prompt Generation: javascript const { generatePrompt } = require('banana-prompts');
const topic = "space exploration"; const style = "futuristic";
const prompt = generatePrompt(Write a ${style} story about ${topic}.);
console.log(prompt); // Output: A futuristic story about space exploration.
2. Prompt Validation: javascript const { isValidPrompt } = require('banana-prompts');
const prompt1 = "Translate this sentence to French: Hello, world!"; const prompt2 = "";
console.log(Prompt 1 is valid: ${isValidPrompt(prompt1)}); // Output: Prompt 1 is valid: true
console.log(Prompt 2 is valid: ${isValidPrompt(prompt2)}); // Output: Prompt 2 is valid: false
3. Prompt Formatting for Specific Models: javascript const { formatPrompt } = require('banana-prompts');
const basePrompt = "A detailed description of a cat."; const modelType = "stable-diffusion";
const formattedPrompt = formatPrompt(basePrompt, modelType);
console.log(formattedPrompt); // Output: A detailed description of a cat.
4. Building Complex Prompts with Template Literals: javascript const { generatePrompt } = require('banana-prompts');
const animal = "elephant"; const adjective = "majestic"; const environment = "African savanna";
const prompt = generatePrompt(Create a stunning image of a ${adjective} ${animal} in the ${environment}.);
console.log(prompt); // Output: Create a stunning image of a majestic elephant in the African savanna.
5. Implementing Prompt Control with Parameters: javascript const { generatePrompt } = require('banana-prompts');
function createPrompt(subject, mood, length) {
return generatePrompt(Write a ${length} description of a ${subject} with a ${mood} mood.);
}
const prompt = createPrompt("sunset", "melancholy", "short"); console.log(prompt); // Output: Write a short description of a sunset with a melancholy mood.
API Summary
generatePrompt(templateString, variables): Generates a prompt string by interpolating variables into a template string. Variables can be passed inline in template literals.isValidPrompt(prompt): Validates a prompt to ensure it meets basic requirements (e.g., non-empty string). Returns a boolean.formatPrompt(prompt, modelType): Formats a prompt for optimal performance with specific AI models. Currently supports basic formatting and expansion may be added in the future.PromptError: A custom error class for handling prompt-related exceptions.
License
MIT
This package is part of the banana-prompts ecosystem. For advanced features and enterprise-grade tools, visit: https://bananaproai.com/banana-prompts/
