Skip to main content

AIPrompts

This is a simple prompt builder for OpenAI models. Easy to use and to modify.

Install

pip install AIPrompts

pip install AIPrompts@git+https://github.com/TeiaLabs/prompts.git@master

Dynamic prompts

template = 'a photo of a <img_label>'
prompt = DynamicPrompt(template)
filled_prompt = prompt.build(img_label='dog')
print(filled_prompt)
# out: "a photo of a dog"

Dynamic prompts from file templates

Build your own prompt by creating a file following a sample.prompt file (yaml format), and use the DynamicPrompt class to parse it:

prompt = DynamicPrompt.from_file('samples/sample.prompt')
str_prompt = prompt.build(
    input_sentence="lets go",
)

You can also access recommended model settings (engine, temperature) that can be fed to the model input (e.g., openai.Completion.create()):

prompt.get_model_settings()

Improve Autocomplete with custom prompts

Alternatively, to get more control and better autocomplete suggestions, you can inherit from the BasePrompt class and override the build method with explicit arguments:

class MyPrompt(BasePrompt):

    def build(self, input_sentence):
        return self.set_prompt_values(
            input_sentence=input_sentence,
        )

Ensembling prompts

To ensemble multiple prompts, you can use the PromptEnsemble class:

templates = [
    '<label>', 
    'a photo of <label>', 
    'picture of <label>',
]
exp_vars = ['label']
prompt = PromptEnsemble(templates, exp_vars)
prompt.build(label='dog')
# out: ['dog', 'a photo of dog', 'picture of dog']
prompt.build(label='cat')
# out: ['cat', 'a photo of cat', 'picture of cat']

The output is a flattened list with all filled in templates. Note: all templates must be filled with the same expected variables, and all variables must be provided.

You can also build multiple promtps at the same time (useful for classification):

templates = [
    '<label>',
    'a photo of <label>'
]
template_vars = [
    'label'
]
labels = ['dog', 'cat', 't-shirt']
prompt = PromptEnsemble(templates, template_vars)
prompt.build_many(
    label=labels
)
# out: ['dog', 'a photo of dog', 'cat', 'a photo of cat', 't-shirt', 'a photo of t-shirt']

Metadata

Release files for AIPrompts 0.5.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for AIPrompts 0.5.6
File Size Uploaded
AIPrompts-0.5.6.tar.gz 9.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for AIPrompts 0.5.6
File Interpreter ABI Platform
AIPrompts-0.5.6-py3-none-any.whl Python 3 none any Details

Total release size: 17.3 kB

Release files / AIPrompts-0.5.6.tar.gz

Download URL AIPrompts-0.5.6.tar.gz
Size 9.2 kB
Tags Source
SHA-256 checksum
How to use checksums
7c72b204dd99ac54802295ecc19756e945be17db5cbbfe986355bc761d038233
BLAKE2b-256 checksum
How to use checksums
0bf0955ff4b80a42e78d5f6fe0f5e00f7544ce7f9833c7cdac9197ec8677e36b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.11.8

Release files / AIPrompts-0.5.6-py3-none-any.whl

Download URL AIPrompts-0.5.6-py3-none-any.whl
Size 8.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b1477bc0944bc8d3ec99f11dd7839a2cecdf7f45529e466d5600b1812a8eb7b1
BLAKE2b-256 checksum
How to use checksums
7b5aa2efd5722265ae366cad828d9d0ba09b9cf0cbe7fe78d43a2ec154a9bce7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.11.8

Release history Release notifications | RSS feed

This release

0.5.6 This release

2 release files

0.5.5

2 release files

0.5.4

2 release files

0.5.3

2 release files

0.5.2

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page