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"}
Metadata
Release files for prompt4py 0.0.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| prompt4py-0.0.6.tar.gz | 4.8 kB | Without provenance | Details for prompt4py-0.0.6.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| prompt4py-0.0.6-py3-none-any.whl | Python 3 | none | any | Details for prompt4py-0.0.6-py3-none-any.whl |
Total release size: 10.6 kB
Release files / prompt4py-0.0.6.tar.gz
| Download URL | prompt4py-0.0.6.tar.gz |
|---|---|
| Size | 4.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3454ed4bbb5c09af527fd813782180d40f49846e166b8eaf2261de02fe0aa9dd
|
|
BLAKE2b-256 checksum How to use checksums |
4287f3b1465277fef950b0f08cf8ed6ffe1b19cf00d0c1cb1dd007224d2673cb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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}
|
Release files / prompt4py-0.0.6-py3-none-any.whl
| Download URL | prompt4py-0.0.6-py3-none-any.whl |
|---|---|
| Size | 5.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
95bc58441e3455789650db0a63dd0c0eefd9802eecfc349e9d032d83bff936bb
|
|
BLAKE2b-256 checksum How to use checksums |
4cac631ba87c557207fc0f4ffd0e91d1d0c659b489fcb7f16800b9139f2c0993
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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}
|
Security for prompt4py 0.0.6
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.