AIPrompts


NameAIPrompts JSON
Version 0.5.6 PyPI version JSON
download
home_pagehttps://github.com/TeiaLabs/prompts
SummaryCreate and parse prompts for large language models.
upload_time2024-03-06 18:06:32
maintainer
docs_urlNone
authorTeialabs
requires_python>=3.10
license
keywords prompt openai teialabs gpt3
VCS
bugtrack_url
requirements pyaml pytest pydantic
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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

```python
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:

```python
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()):

```python
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:

```python
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:

```python
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):

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

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/TeiaLabs/prompts",
    "name": "AIPrompts",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": "",
    "keywords": "prompt openai teialabs gpt3",
    "author": "Teialabs",
    "author_email": "jonatas@teialabs.com",
    "download_url": "https://files.pythonhosted.org/packages/0b/f0/955ff4b80a42e78d5f6fe0f5e00f7544ce7f9833c7cdac9197ec8677e36b/AIPrompts-0.5.6.tar.gz",
    "platform": null,
    "description": "# AIPrompts\n\nThis is a simple prompt builder for OpenAI models. Easy to use and to modify.\n\n## Install\n\n`pip install AIPrompts`\n\n`pip install AIPrompts@git+https://github.com/TeiaLabs/prompts.git@master`\n\n## Dynamic prompts\n\n```python\ntemplate = 'a photo of a <img_label>'\nprompt = DynamicPrompt(template)\nfilled_prompt = prompt.build(img_label='dog')\nprint(filled_prompt)\n# out: \"a photo of a dog\"\n```\n\n## Dynamic prompts from file templates\n\nBuild your own prompt by creating a file following a sample.prompt file (yaml format), and use the DynamicPrompt class to parse it:\n\n```python\nprompt = DynamicPrompt.from_file('samples/sample.prompt')\nstr_prompt = prompt.build(\n    input_sentence=\"lets go\",\n)\n```\n\nYou can also access recommended model settings (engine, temperature) that can be fed to the model input (e.g., openai.Completion.create()):\n\n```python\nprompt.get_model_settings()\n```\n\n## Improve Autocomplete with custom prompts\n\nAlternatively, to get more control and better autocomplete suggestions, you can inherit from the `BasePrompt` class and override the build method with explicit arguments:\n\n```python\nclass MyPrompt(BasePrompt):\n\n    def build(self, input_sentence):\n        return self.set_prompt_values(\n            input_sentence=input_sentence,\n        )\n```\n\n## Ensembling prompts\n\nTo ensemble multiple prompts, you can use the `PromptEnsemble` class:\n\n```python\ntemplates = [\n    '<label>', \n    'a photo of <label>', \n    'picture of <label>',\n]\nexp_vars = ['label']\nprompt = PromptEnsemble(templates, exp_vars)\nprompt.build(label='dog')\n# out: ['dog', 'a photo of dog', 'picture of dog']\nprompt.build(label='cat')\n# out: ['cat', 'a photo of cat', 'picture of cat']\n```\n\nThe output is a flattened list with all filled in templates.\nNote: all templates must be filled with the same expected variables, and all variables must be provided.\n\nYou can also build multiple promtps at the same time (useful for classification):\n\n```python\ntemplates = [\n    '<label>',\n    'a photo of <label>'\n]\ntemplate_vars = [\n    'label'\n]\nlabels = ['dog', 'cat', 't-shirt']\nprompt = PromptEnsemble(templates, template_vars)\nprompt.build_many(\n    label=labels\n)\n# out: ['dog', 'a photo of dog', 'cat', 'a photo of cat', 't-shirt', 'a photo of t-shirt']\n```\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Create and parse prompts for large language models.",
    "version": "0.5.6",
    "project_urls": {
        "Homepage": "https://github.com/TeiaLabs/prompts"
    },
    "split_keywords": [
        "prompt",
        "openai",
        "teialabs",
        "gpt3"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7b5aa2efd5722265ae366cad828d9d0ba09b9cf0cbe7fe78d43a2ec154a9bce7",
                "md5": "84210751bebb71ca8ae9c1399c2d2813",
                "sha256": "b1477bc0944bc8d3ec99f11dd7839a2cecdf7f45529e466d5600b1812a8eb7b1"
            },
            "downloads": -1,
            "filename": "AIPrompts-0.5.6-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "84210751bebb71ca8ae9c1399c2d2813",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 8063,
            "upload_time": "2024-03-06T18:06:30",
            "upload_time_iso_8601": "2024-03-06T18:06:30.975890Z",
            "url": "https://files.pythonhosted.org/packages/7b/5a/a2efd5722265ae366cad828d9d0ba09b9cf0cbe7fe78d43a2ec154a9bce7/AIPrompts-0.5.6-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0bf0955ff4b80a42e78d5f6fe0f5e00f7544ce7f9833c7cdac9197ec8677e36b",
                "md5": "ccc6528c0eda0ba233b8f2abe1b6f7ca",
                "sha256": "7c72b204dd99ac54802295ecc19756e945be17db5cbbfe986355bc761d038233"
            },
            "downloads": -1,
            "filename": "AIPrompts-0.5.6.tar.gz",
            "has_sig": false,
            "md5_digest": "ccc6528c0eda0ba233b8f2abe1b6f7ca",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 9242,
            "upload_time": "2024-03-06T18:06:32",
            "upload_time_iso_8601": "2024-03-06T18:06:32.552881Z",
            "url": "https://files.pythonhosted.org/packages/0b/f0/955ff4b80a42e78d5f6fe0f5e00f7544ce7f9833c7cdac9197ec8677e36b/AIPrompts-0.5.6.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-06 18:06:32",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "TeiaLabs",
    "github_project": "prompts",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "pyaml",
            "specs": []
        },
        {
            "name": "pytest",
            "specs": []
        },
        {
            "name": "pydantic",
            "specs": []
        }
    ],
    "lcname": "aiprompts"
}
        
Elapsed time: 0.25772s