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.
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 .
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!
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.
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!
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
from flexi_prompt import FlexiPrompt
fp = FlexiPrompt()
inner_fp = FlexiPrompt({"another_field1": "nested value1, "})
inner_fp.another_field2 = "nested value2"
inner_fp.another_field1().another_field2()
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
- 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.
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.
-
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
hatch
for testing. You can run the tests with:hatch run test
Thank you for considering contributing to FlexiPrompt!
The FlexiPrompt is open-sourced software licensed under the MIT license.