No project description provided
Project description
Folio
Folio is a CLI and Python-based library for managing and storing prompt templates with versioning capabilities. It supports Jinja2-based templating for dynamic prompt rendering, leveraging TinyDB for lightweight data storage and easy-to-use methods for listing, retrieving, and managing prompt versions.
Features
-
Prompt Versioning: Automatically manage and version prompts as you add or modify them. Folio increments version numbers for each updated prompt, keeping track of the entire prompt history.
-
LLM Agnostic : Folio does not directly interact with any LLM. It only manages your prompts for you. So, you can use it with any LLM.
-
Templating with Jinja2: Folio uses Jinja2 templating syntax, enabling dynamic text generation. Easily include variables within prompts for customizable outputs. The biggest advantage is that you can create your own templates which can be composed to form new prompts leading to better organisation and reduced prompt redundancy.
-
CLI and Python API Support: Manage prompts directly from the command line or use Folio’s Python API for programmatic access and automation.
Installation
To install folio, download the latest release from the GitHub repository:
https://github.com/neshkatrapati/folio
After downloading, install the package with:
pip install path/to/folio-release.whl
CLI Commands
-
Initialize a Folio Project
This command initializes the
folioproject in the current directory, creating the necessary folders and database.folio init -
Add a New Prompt
To add a prompt from a file:
folio add <prompt_name> --file path/to/prompt.txt
Or by piping from standard input:
echo "Prompt text goes here" | folio add <prompt_name>
You may add variable using the Jinja2 template format like this.
echo "Write a haiku about {{ topic }} " | folio add <prompt_name>
-
List All Prompts
To list all prompts with their respective versions:
folio list-prompts -
List All Versions of a Prompt
This lists all versions for a specific prompt:
folio list-versions <prompt_name>
-
Show a Prompt Version
Retrieve and display a specific version of a prompt:
folio show <prompt_name> --version <version_number>
If the version is omitted, it retrieves the latest version. You can also render a prompt with specific variables:
folio show <prompt_name> --version <version_number> --render '{"key": "value"}'
-
Delete a Prompt Version
Deletes a specified version of a prompt:
folio delete-version <prompt_name> --version <version_number>
To delete the latest version:
folio delete-version <prompt_name> --latest
Using Folio in Python
Folio also provides a Python API for managing prompts programmatically. Below is an example demonstrating how to initialize Folio, add prompts, and use templating with Jinja2 for prompt rendering.
Example Workflow
-
Initialize Folio
from folio import Folio # Initialize Folio and create necessary directories and files folio = Folio.init()
-
Add a New Prompt with Templating
Folio uses Jinja2 templating syntax, allowing you to include variables in prompt templates. This example adds a prompt with a placeholder for the recipient's name.
from datetime import datetime prompt_text = "Write a haiku about {{ topic }}" folio.add_prompt("song", prompt_text)
-
Retrieve and Render a Prompt
You can retrieve the latest version of a prompt and render it with specific values using Jinja2 syntax.
# Get the latest version of the prompt and render with variables rendered_prompt = folio.get_prompt( "song", render={"topic" : "Generative AI"} ) print(rendered_prompt.text) # Output: Hello, Alice! Today is 2024-11-03.
-
Add a New Version of the Prompt
Folio automatically increments the version when you update a prompt:
updated_prompt_text = "Compose a poem on {{ topic }} in {{ num_lines }} lines" folio.add_prompt("song", updated_prompt_text)
-
List All Versions of a Prompt
Retrieve and display all versions of a specific prompt, along with their creation dates.
versions = folio.list_versions_by_prompt("song") for version in versions: print(f"Version {version.version} created on {version.created_at}")
-
Delete a Specific Version of a Prompt
Folio allows you to delete a specific version or the latest version of a prompt:
folio.delete_version("song", version=1)
Prompt Inheritance
Folio allows Jinja2 based prompt inheritance. For example
{# prompt: cot/latest #}
{% block task %}
{% endblock %}
{% block problem_statement %}
{% endblock %}
{% block examples %}
Here are some examples
{% for example in examples %}
** Example {{ loop.index }} ** : {{ example }}
{% endfor %}
{% endblock %}
Let's think step by step
{% block ensure_output_format %}
{% endblock %}
This can be then extended in other templates
{# prompt: ner/latest #}
{% extends 'cot/latest' %}
{% block task %}
Your task is to perform Named Entity Detection.
{% endblock %}
{% block problem_statement %}
Here is some text : {{ text }}
Detect the following entities:
- Name
- Organisation
- Currency
- Email
{% endblock %}
{% block ensure_output_format %}
Ensure the output is in JSON. Do not generate any markdown.
{% endblock %}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file folioprompts-0.2.0.tar.gz.
File metadata
- Download URL: folioprompts-0.2.0.tar.gz
- Upload date:
- Size: 8.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.4 CPython/3.11.7 Darwin/24.1.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
625f65c33f5895a4e1c85fa824568410ccfc65b54708eba4e1a3fe2212b5c92f
|
|
| MD5 |
9355f3d20fd2483bf43b2d3f37d3285b
|
|
| BLAKE2b-256 |
e765e17e13b2abd2a40b1988003ba8538d0edbf5d538c826654e0fd0c2e692ea
|
File details
Details for the file folioprompts-0.2.0-py3-none-any.whl.
File metadata
- Download URL: folioprompts-0.2.0-py3-none-any.whl
- Upload date:
- Size: 10.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.4 CPython/3.11.7 Darwin/24.1.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8151e19c9e01ace4c34fd705bbabac386e90a63887fcbb242943affad88c04cf
|
|
| MD5 |
31cc304aff1aedcf2f6f73f93b2eb5db
|
|
| BLAKE2b-256 |
fba6e4c5497b5c0868545074471fa7976af212ea19c49444ca4795d88740ed94
|