Skip to main content

Create and parse prompts for large language models.

Project description

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']

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

AIPrompts-0.5.2.tar.gz (8.9 kB view details)

Uploaded Source

Built Distribution

AIPrompts-0.5.2-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file AIPrompts-0.5.2.tar.gz.

File metadata

  • Download URL: AIPrompts-0.5.2.tar.gz
  • Upload date:
  • Size: 8.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.11

File hashes

Hashes for AIPrompts-0.5.2.tar.gz
Algorithm Hash digest
SHA256 88c6caf1fdf38ade1bc68e3af0eddbb5a6f5aa500700da74623ac6b4cd97a09c
MD5 fe453010426a9df237f58b8353ee66c3
BLAKE2b-256 6c6a2e94b62216ef68fe2f477cb630b2877ca6653c26f76a080d4b2faaeb22a3

See more details on using hashes here.

File details

Details for the file AIPrompts-0.5.2-py3-none-any.whl.

File metadata

  • Download URL: AIPrompts-0.5.2-py3-none-any.whl
  • Upload date:
  • Size: 7.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.11

File hashes

Hashes for AIPrompts-0.5.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4b49acc11fa2a36295be797df17201e79cbcc029a2b5568c66ef790088a3e81a
MD5 734c0fb97c658912e6395fb841c619d3
BLAKE2b-256 7d54b84ae0a6b516edb8627b2c93db61943da649ae13bfc01b6e02f067a299dd

See more details on using hashes here.

Supported by

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