A flexible prompt builder for AI applications
Project description
FlexiPrompt
FlexiPrompt is a flexible and powerful templating library, allowing you to create and manage text prompts with ease. It supports nested templates, prevents infinite recursion, and provides a simple yet powerful API for building complex text prompts.
Installation
To install FlexiPrompt, you can use pip. First, ensure you have Python 3.12 or later installed.
pip install flexi-prompt
Alternatively, you can build and install the project from the source by running:
git clone https://github.com/VELIKII-DIVAN/flexi_prompt.git
cd flexi_prompt
pip install .
Documentation
Basic Usage
Here's a simple example to get you started:
from flexi_prompt import FlexiPrompt
fp = FlexiPrompt()
fp.greeting = "Hello, $name!"
fp.name = "John"
print(fp.greeting().build()) # Output: Hello, John!
Nested Templates
FlexiPrompt supports nested templates:
fp1 = FlexiPrompt()
fp1.introduction = "I am $age years old."
fp1.age = 30
fp1.introduction()
fp = FlexiPrompt()
fp.greeting = "Hello, $name! $introduction"
fp.name = "John"
fp.introduction = fp1
print(fp.greeting().build()) # Output: Hello, John! I am 30 years old.
External Functions
You can also use external functions in your templates:
def get_name():
# any useful actions
# ...
return "John"
fp = FlexiPrompt()
fp.greeting = "Hello, $name!"
fp.name = get_name
print(fp.greeting().build()) # Output: Hello, John!
Preventing Infinite Recursion
FlexiPrompt ensures that templates do not cause infinite recursion:
fp = FlexiPrompt()
fp.greeting = "Hello, $name!"
fp.name = "$greeting"
try:
fp.greeting().build()
except ValueError as e:
print(e) # Output: Template recursion detected
All in one
from flexi_prompt import FlexiPrompt
fp = FlexiPrompt()
inner_fp = FlexiPrompt({"another_field1": "nested value1, "})
inner_fp.another_field2 = "nested value2"
fp.final_prompt = "Here is: $inner_fp, $some_field, $some_callback"
fp.inner_fp = inner_fp
fp.some_field = 42
fp.some_callback = input # For example input = "user input"
print(fp.final_prompt().build())
# Here is: nested value1, nested value2, 42, user input
Features
- Flexible Templating: Create and manage text prompts with ease.
- Nested Templates: Support for nesting templates within each other.
- External Functions: Use external functions in your templates.
- Recursion Detection: Prevent infinite recursion in templates.
Contributing
We welcome contributions to FlexiPrompt! Here are some ways you can help:
- Report Bugs: If you encounter any issues, please report them on our issue tracker.
- Submit Pull Requests: If you have a fix or new feature, feel free to submit a pull request. Please ensure your code follows our coding standards and includes tests.
- Improve Documentation: Help us improve our documentation to make it easier for others to use FlexiPrompt.
Setting Up Your Development Environment
-
Clone the repository:
git clone https://github.com/VELIKII-DIVAN/flexi_prompt.git cd flexi_prompt
-
Install dependencies:
pip install -e .[test]
-
Run Tests:
We use
hatchfor testing. You can run the tests with:hatch run test
Thank you for considering contributing to FlexiPrompt!
License
The FlexiPrompt is open-sourced software licensed under the MIT license.
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 flexi_prompt-0.1.0.tar.gz.
File metadata
- Download URL: flexi_prompt-0.1.0.tar.gz
- Upload date:
- Size: 4.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ed4bd40ab5122769239d8dd056a131985ca2aec335098438a1d2641386c3f728
|
|
| MD5 |
1b90304f21999c1b2f1809c65f09140f
|
|
| BLAKE2b-256 |
f34ac930b339c141de7ced6a98a1ca5a126f0c34128cc51828acc1508e36b07c
|
File details
Details for the file flexi_prompt-0.1.0-py3-none-any.whl.
File metadata
- Download URL: flexi_prompt-0.1.0-py3-none-any.whl
- Upload date:
- Size: 3.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8d07a1378a9442d2440da91a96de343645bf9889256d8f1ec7332bb00a2923db
|
|
| MD5 |
d483cb0bef2aab4998280828c24601e1
|
|
| BLAKE2b-256 |
02f7baf81b3fa0e750b326d7e76616bcb9a9b0520f4d2f8344b3c31eed4c36e1
|