Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/p0u4a/prompto
Programmatically construct ChatGPT prompts with TypeScript
https://github.com/p0u4a/prompto
chatgpt gpt javascript llm npm-package prompt-engineering prompts typescript
Last synced: about 1 month ago
JSON representation
Programmatically construct ChatGPT prompts with TypeScript
- Host: GitHub
- URL: https://github.com/p0u4a/prompto
- Owner: P0u4a
- License: mit
- Created: 2023-07-07T12:41:41.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-10-12T15:09:15.000Z (about 1 year ago)
- Last Synced: 2024-09-18T13:44:16.286Z (3 months ago)
- Topics: chatgpt, gpt, javascript, llm, npm-package, prompt-engineering, prompts, typescript
- Language: TypeScript
- Homepage:
- Size: 55.7 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Prompto ✒️
Programatically construct ChatGPT prompts with Typescript. Think of it as a SQL query builder except instead of SQL queries, its LLM prompts.
## Features
- ✅ Zero dependencies
- ✅ Resistant to prompt injection
- ✅ Blazingly fast prompt generation## Installation
```
npm install ts-prompto
```## Usage
Create a Prompto object anywhere and use method chaining to build your prompt:
```ts
const prompt = new Prompto()
.withPersona("Openai engineer")
.withInstruction("Explain how to write effective ChatGPT prompts")
.inFormat("step-by-step guide")
.generatePrompt();console.log(prompt);
```## API
### `Prompto()`
Creates an empty prompt config with a blank instruction.
### `withPersona(persona: string)`
Sets the persona that the model will take on.
### `withInstruction(question: string)`
Sets the main instruction or request the model will respond to. This is a **compulsory** method.
### `withContext(context: string)`
Provides additional context or information for the model to consider while generating a response.
### `withText(content: string[])`
Adds any text that the model needs to parse through (i.e., an article to summarize or a code snippet to explain).
### `withSteps(steps: string[])`
Adds the specific set of steps required to reach an output. Helpful for guiding the model to reach its output, allowing the model to 'think' more about its response.
### `withExamples(examples: string[])`
Adds a list of example outputs for the model to be aware of via [few-shot prompting](https://www.promptingguide.ai/techniques/fewshot). Helpful if you need a specific or complicated output.
### `inFormat(format: string)`
Adds the expected format of the response (i.e., step-by-step instructions, JSON, TypeScript code, etc.)
### `withCriteria(criteria: string[])`
Adds a list of rules that the model must follow to reach its output. Helpful for setting constraints on what the output should not include or for handling cases for user-inputted instructions.
### `inTone(tone: string)`
Sets the tone of the response. Helpful if you're writing text that requires an appropriate tone, such as an email.
### `generatePrompt()`
Generates the prompt using the prompt config. This is the final method that should be called in the chain. Also clears the prompt config before returning the prompt string, allowing for the same Prompto
instance to be used for generating different prompts.