https://github.com/helicone/prompts
https://github.com/helicone/prompts
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/helicone/prompts
- Owner: Helicone
- Created: 2024-07-17T21:34:28.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2025-03-12T05:39:52.000Z (about 1 year ago)
- Last Synced: 2025-03-26T11:44:45.378Z (about 1 year ago)
- Language: TypeScript
- Size: 134 KB
- Stars: 7
- Watchers: 1
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Helicone Prompts
Helicone Prompt Formatter is a robust library designed to format JSON objects for Large Language Model (LLM) applications. It offers a streamlined approach to handling prompt templates, variable management, and versioning.
## Key Features
1. Automated versioning of new prompts with change detection based on a structured framework
2. Seamless handling of chat-like prompt templates
3. Efficient extraction and insertion of variables into prompts
## Motivation
Existing prompt formatting libraries often fall short in addressing the following challenges:
1. Limited support for chat-like prompt templates
2. Inadequate variable handling mechanisms
3. Insufficient array management capabilities
HPF aims to bridge these gaps, providing a comprehensive solution for LLM prompt formatting.
## Quick Start
Install the library using your preferred package manager:
```bash
# JavaScript/TypeScript
yarn add @helicone/prompts
# OR
npm install @helicone/prompts
# Python
pip install helicone_prompts
# OR
poetry add helicone_prompts
```
### Basic Usage
```javascript
// JavaScript/TypeScript
import { hpf } from "@helicone/prompts";
const promptWithInputs = hpf`
Hello ${{ world: "variable" }}
`;
console.log(promptWithInputs);
// Output: 'Hello variable'
```
```python
# Python
from helicone_prompts import hpf
prompt_with_inputs = hpf("Hello {world}", world="variable")
print(prompt_with_inputs)
# Output: 'Hello variable'
```
### Variable Extraction
```javascript
// JavaScript/TypeScript
import { parsePrompt } from "@helicone/prompt-formatter";
const { variables, prompt, text } = parsePrompt(
'Hello variable'
);
console.log(variables); // { world: "variable" }
console.log(prompt); // 'Hello '
console.log(text); // "Hello variable"
```
```python
# Python
from helicone_prompts import parse_prompt
result = parse_prompt('Hello variable')
print(result["variables"]) # { "world": "variable" }
print(result["prompt"]) # 'Hello '
print(result["text"]) # "Hello variable"
```
### Variable Insertion
```javascript
// JavaScript/TypeScript
import { autoFillInputs } from "@helicone/prompt-formatter";
const result = autoFillInputs({
inputs: {
world: "variable",
},
template: `Hello `,
autoInputs: [],
});
console.log(result); // "Hello variable"
```
```python
# Python
from helicone_prompts import auto_fill_inputs
result = auto_fill_inputs(
inputs={"world": "variable"},
template='Hello ',
auto_inputs=[]
)
print(result) # "Hello variable"
```
## LLM Object Handling
HPF utilizes a custom variant of JSX developed by Helicone to manage LLM objects effectively.
### Example
```javascript
// JavaScript/TypeScript
const obj = {
model: "gpt-4-turbo",
messages: [
{
role: "system",
content:
'Test input 1',
},
{
role: "user",
content: [
{
type: "image_url",
image_url: {
url: "...",
detail: "high",
},
},
],
},
{
role: "assistance",
content:
'Using the content above and given that input 2, what are the images?',
},
],
max_tokens: 700,
};
const { objectWithoutJSXTags, templateWithInputs } = parseJSXObject(obj, {
ignoreFields: ["max_tokens", "model"],
});
```
```python
# Python
from helicone_prompts import parse_jsx_object, ParseJSXObjectOptions
obj = {
"model": "gpt-4-turbo",
"messages": [
{
"role": "system",
"content": 'Test input 1',
},
{
"role": "user",
"content": [
{
"type": "image_url",
"image_url": {
"url": "...",
"detail": "high",
},
},
],
},
{
"role": "assistance",
"content": 'Using the content above and given that input 2, what are the images?',
},
],
"max_tokens": 700,
}
result = parse_jsx_object(obj, ParseJSXObjectOptions(ignore_fields=["max_tokens", "model"]))
object_without_jsx_tags = result["objectWithoutJSXTags"]
template_with_inputs = result["templateWithInputs"]
```
For more detailed information on usage and advanced features, please refer to our comprehensive documentation.