Programmatic prompt template for Python.
Project description
Prompt4Py
Programmatic prompt template for Python.
Installation
pip install -U prompt4py
Quick Start
-
Create a prompt template
from prompt4py import GeneralTemplate # Create your prompt template prompt_template = GeneralTemplate() prompt_template.role = 'An NER machine' prompt_template.objective = 'Extract all {{entity_type}} from CONTEXT.' prompt_template.instruction = { 1: 'Think deeply on every entities in CONTEXT', 2: 'Extract all {{entity_type}}', 3: 'Output the entities you have extracted' } prompt_template.constraint = 'Do not include any markdown grams' prompt_template.capability = 'Extract entities' prompt_template.context = '{{ent_1}}, {{ent_2}}, {{ent_3}}' prompt_template.output_dtype = 'str' prompt_template.output_format = 'jsonl' prompt_template.output_example = str([ { 'entity_type': '{{example_entity_type_1}}', 'entity_text': '{{example_entity_text_1}}' } ])
-
Render the template
# Render the template prompt = prompt_template.render(entity_type='PERSON', ent_1='John Lennon', ent_2='Joe Biden', ent_3='Charlemagne', example_entity_type_1='PERSON', example_entity_text_1='Elizabeth') print(prompt)
the prompt would be rendered like this:
## _TIMESTAMP [82159.8475038] ## ROLE An NER machine ## OBJECTIVE Extract all PERSON from CONTEXT. ## INSTRUCTION - **1**: Think deeply on every entities in CONTEXT - **2**: Extract all PERSON - **3**: Output the entities you have extracted ## CONSTRAINT Do not include any markdown grams ## CAPABILITY Extract entities ## CONTEXT John Lennon, Joe Biden, Charlemagne ## OUTPUT_DATATYPE str ## OUTPUT_FORMAT jsonl ## OUTPUT_EXAMPLE [{'entity_type': 'PERSON', 'entity_text': 'Elizabeth'}]
-
Invoke a chatbot / causal language model
You would get response like below:
{"entity_type": "PERSON", "entity_text": "John Lennon"} {"entity_type": "PERSON", "entity_text": "Joe Biden"} {"entity_type": "PERSON", "entity_text": "Charlemagne"}
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
prompt4py-0.0.1.tar.gz
(4.5 kB
view details)
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 prompt4py-0.0.1.tar.gz.
File metadata
- Download URL: prompt4py-0.0.1.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d5fa32262e7cb7cec3cb1277fccf560045158952460027c64481edd4cef23d16
|
|
| MD5 |
00ef031ae5cc94ee1001b8cea3473bf3
|
|
| BLAKE2b-256 |
d725e260521ef93c0afa7331d6d04f8a34759aad39311ef91b379933a11aeecc
|
File details
Details for the file prompt4py-0.0.1-py3-none-any.whl.
File metadata
- Download URL: prompt4py-0.0.1-py3-none-any.whl
- Upload date:
- Size: 5.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bfd7b7db916979f9cf5f8761c5c912a6123f7fa82afd289da6ecf75b6c0d5a32
|
|
| MD5 |
7c504999eed7e86fb35a4c711bcb9f0a
|
|
| BLAKE2b-256 |
7439e6a961a925d5c68ec8983db3a7c84119038fde708d1b506611e2eaa9355b
|