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.6.tar.gz
(4.8 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.6.tar.gz.
File metadata
- Download URL: prompt4py-0.0.6.tar.gz
- Upload date:
- Size: 4.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.2 {"installer":{"name":"uv","version":"0.11.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3454ed4bbb5c09af527fd813782180d40f49846e166b8eaf2261de02fe0aa9dd
|
|
| MD5 |
11aa514931f1e1b102af512f6c4c8b19
|
|
| BLAKE2b-256 |
4287f3b1465277fef950b0f08cf8ed6ffe1b19cf00d0c1cb1dd007224d2673cb
|
File details
Details for the file prompt4py-0.0.6-py3-none-any.whl.
File metadata
- Download URL: prompt4py-0.0.6-py3-none-any.whl
- Upload date:
- Size: 5.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.2 {"installer":{"name":"uv","version":"0.11.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
95bc58441e3455789650db0a63dd0c0eefd9802eecfc349e9d032d83bff936bb
|
|
| MD5 |
a664e1cb633a4e997db7bb350461e4e9
|
|
| BLAKE2b-256 |
4cac631ba87c557207fc0f4ffd0e91d1d0c659b489fcb7f16800b9139f2c0993
|