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.2.tar.gz (4.7 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.2-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for prompt4py-0.0.2.tar.gz
Algorithm Hash digest
SHA256 1a1f3219e245bf1f9918fe801e1a70ce55f7a62efc964b833b8305c420608395
MD5 8926c1309e875a2afc2cf88cc8511d9c
BLAKE2b-256 6c6d6c8dc49e94d19ecc991c6a3bca1716ebbe911a8ae29ef6842f9abba3166d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: prompt4py-0.0.2-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

Hashes for prompt4py-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 2d5eea71b10fe01ac32f84603fa9b2a2c95f7a3607bba673fe95a6137f755c7d
MD5 11d1f8618785719885e6487009916961
BLAKE2b-256 8df0c6f07aec70ddd158bf087f5b60ad31451357bf4c9e7d503f571c10dd0859

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