GithubHelp home page GithubHelp logo

lguzzon-scratchbook / prompt-compose Goto Github PK

View Code? Open in Web Editor NEW

This project forked from anubhavgupta/prompt-compose

0.0 0.0 0.0 58 KB

A JS library that provides basic axioms for building and managing GPT prompts. No dependencies.

JavaScript 100.00%

prompt-compose's Introduction

prompt-compose

This library provides basic axioms for building and managing GPT prompts. It helps you build small and resuable prompt components and then let you compose them together to build larger ones.

Installation:

NodeJS:

npm install prompt-compose

Basic axioms for building prompts:

Statement

Creates a simple line of text. It is a basic building block for building larger prompts.

const question = Statement("How to make a website?");
question();
// "How to make a website?"

Section

Creates a new section of text with title and content.

const problemSection = Section(
    Statement("Problem Statement"),
    Statement("How to make a website?")
);

problemSection();
//  
// Problem Statement:
//     How to make a website?

Format

Asks for a data structure and creates a prompt where it asks GPT to return the response in the given format.

const formatTheReponse = Format([
    {
        stepIndex: "<number>",
        stepDetails: "<string>"
    }
]);

formatTheReponse();
// `Answer should be in a valid JSON, use the following structure: 
//     ResponseJSON: [{"stepIndex":"<number>","stepDetails":"<string>"}]`

System

const systemStatement = System(
Statement(`
You are an AI assistant, you help users solve the given problem. 
- Your answeres are brief and to the point.
- You only answer in the format given by the user.
- If you don't know the answer to a question, you truthfully say that I don't know it. 
- You can end your answer with "END_END_END" text.`)
);

systemStatement();

// `System:
//    
//     You are an AI assistant, you help users solve the given problem. 
//     - Your answeres are brief and to the point.
//     - You only answer in the format given by the user.
//     - If you don't know the answer to a question, you truthfully say that I don't know it. 
//     - You can end your answer with "END_END_END" text.`

Compose

Let you compose multiple prompts together.

const makePrompt = compose(
    systemStatement,
    problemSection,
);

makePrompt();

// System:
//    
//     You are an AI assistant, you help users solve the given problem. 
//     - Your answeres are brief and to the point.
//     - You only answer in the format given by the user.
//     - If you don't know the answer to a question, you truthfully say that I don't know it. 
//     - You can end your answer with "END_END_END" text.
 
// Problem Statement:
//     How to make a website?

Divider

Configurable, adds a division between 2 given prompts.

const promptWithDivider = compose(
    Statement("Do task 1."),
    Divider(),
    Statement("Do task 2.")
);
promptWithDivider()

// Do task 1.
// 
// Do task 2.
 

None

An empty input.

const expectedResponse = Section(
        Statement("AI"),
        None()
);
expectedResponse();

// AI:
//   

Example code:

import { System, Section, Format, compose, Statement, None } from "prompt-compose";

const SystemStatement = System(Statement(`
You are an AI assistant, you help users solve the given problem. 
- Your answeres are brief and to the point.
- You only answer in the format given by the user.
- If you don't know the answer to a question, you truthfully say that I don't know it. 
- You can end your answer with "END_END_END" text.
`));

const ResponseFormater =  Section(
    Statement("Format"),
    Format([
        {
          stepIndex: "<number>",
          stepDetails: "<string>"
        }
      ]),
);

const getProblemSolverPromptMaker = ()=>{
    const solverPrompt =  compose(
        SystemStatement,
        Section(
            Statement("User"),
                ResponseFormater,
                Section(Statement("Problem")),
        ),
        Section(
            Statement("AI"),
            None()
        )
    );

    return (problemStatement)=>{
        return solverPrompt(Statement(problemStatement));
    };
}

const problemSolverPromptMaker = getProblemSolverPromptMaker();

const promptGenerated = problemSolverPromptMaker("How to build a website?");

console.log(promptGenerated);
// O/P:
// System:
    
//     You are an AI assistant, you help users solve the given problem. 
//     - Your answeres are brief and to the point.
//     - You only answer in the format given by the user.
//     - If you don't know the answer to a question, you truthfully say that I don't know it. 
//     - You can end your answer with "END_END_END" text.
    
 
// User:
     
//     Format:
//         Answer should be in a valid JSON, use the following structure: 
//             ResponseJSON: [{"stepIndex":"<number>","stepDetails":"<string>"}]
     
//     Problem:
//         How to build a website?
 
// AI:
//     

prompt-compose's People

Contributors

anubhavgupta avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.