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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file AIPrompts-0.5.4.tar.gz
.
File metadata
- Download URL: AIPrompts-0.5.4.tar.gz
- Upload date:
- Size: 9.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7f30688d1b55a28c14acfba6a577481d8543b7aff01b443c90be65a02c0cb1ea |
|
MD5 | 8509bddd9a0ac96cc3f42ebe6d24b4d6 |
|
BLAKE2b-256 | e08e487f512c35e4e610a4d029850ebd6f7dd47724dcf3a80371af3956bb3ae1 |
File details
Details for the file AIPrompts-0.5.4-py3-none-any.whl
.
File metadata
- Download URL: AIPrompts-0.5.4-py3-none-any.whl
- Upload date:
- Size: 7.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1aab78112ba37ee5cd4beebfd309c7a5dd3ca4a71dea2fb7b7df23d83720f61b |
|
MD5 | e7b070dd71147b3faae78a151ee7e345 |
|
BLAKE2b-256 | dac983d08bf9aead87baff8c5eee7a75aca0849b3be235403716d1cd94b5409b |