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.5.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.5-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: prompt4py-0.0.5.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.5.tar.gz
Algorithm Hash digest
SHA256 54ea6987f44f96683a37aabee93b54cf61092d0d3ea6a9d48f87c1ed71f812d3
MD5 177319dbef2459ebd8c7166e9f463145
BLAKE2b-256 4ff8e10cb8541860937cdcaae1b40b9173d3a167dae84da9dce40f951d9e0f30

See more details on using hashes here.

File details

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

File metadata

  • Download URL: prompt4py-0.0.5-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.5-py3-none-any.whl
Algorithm Hash digest
SHA256 01638de81d3a513b05783ede102cb6c4c8d88b4b48db2bebb651bd0b3e96b023
MD5 67279864958588274f36d54f0ab2447a
BLAKE2b-256 963eaf18ceb3e0d2a38a8f1dfe4358764f96eff9490ef6f54baf39cc3b209861

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