Skip to main content

Programmatic prompt template for Python.

Project description

Prompt4Py

Programmatic prompt template for Python.

Installation

pip install -U prompt4py

Quick Start

  1. 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}}'
        }
    ])
    
  2. 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'}]
    
  3. 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.3.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

prompt4py-0.0.3-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file prompt4py-0.0.3.tar.gz.

File metadata

  • Download URL: prompt4py-0.0.3.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.14

File hashes

Hashes for prompt4py-0.0.3.tar.gz
Algorithm Hash digest
SHA256 5827241f9b1451479265f6e2dcb9ff258d8aec7c77742680dfd571aaec598975
MD5 aa998e48c57aa81809b50df5e085098a
BLAKE2b-256 b84cf071c2d4f72c0a0144066111fc655ae3c54d6d82b7044c49bcdaa0420eda

See more details on using hashes here.

File details

Details for the file prompt4py-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: prompt4py-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 5.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.14

File hashes

Hashes for prompt4py-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 9c91d27ecedc5aa266ae39281ed686cc56cc16c7647c7f31bccb32b4b546af2e
MD5 d69290660089a0c1c654ee7318c7782b
BLAKE2b-256 5d4d0bb30b7f868d9a47ac2cfc9002a3fd8c11e696bedc5a1644e5bd58010900

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page