Skip to main content

Module to incorporate .prompt file to your python code for GenAI

Project description

Dotprompt

Dotprompt is a simple library allowing to store your GenAI prompts as .prompt files. It is a simple way to keep your prompts organized and easily accessible alongside your python code.

How to use

Store your prompts as .prompts or .jprompt files in a prompts folder in your at the root of your code directory. Exemple :

my_project/
    my_code.py
    prompts/
        my_prompt.system.prompt
        not_specific.prompt
        my_other_prompt.jprompt

If the prompts folder is not located in the project, uses the method load_folder:

import dotprompt

dotprompt.load_folder("./my_prompt_files")

Then simply import dotprompt in your code and get your prompts as object of dotprompts

import dotprompt

...

res = gen_ai_client.complete(dotprompt.my_prompt.system)

When getting a prompt, the library return it as a string and you can use variables to enrich it.

/* A system prompt with variables {speciality} and {age} */
You are an AI specialized in {speciality}. You are {age} years old.
import dotprompt

res = genai_client.complete(
    prompt = dotprompt.my_prompt.system.format(
        speciality = "medicine",
        age = 3
    )
)

When comments have been add to the prompt files, the dotprompt store it in the info attribute of the prompt object.

import dotprompt

print(dotprompt.my_prompt.info['system'])
>>>"A system prompt with variables {speciality} and {age}"

Files format

.prompt

The .prompt file format is a simple text file containing the prompt as a string.

It uses a second extension to specify the type of prompt in the file.

Example: If you have a prompt with a system prompt and a user prompt, you'll make two files as follows:

  • my_prompt.system.prompt
  • my_prompt.user.prompt

And you'll be able to access them as follows:

import dotprompt

res = gen_ai_client.complete(
    prompt = {
        "system": dotprompt.my_prompt.system, 
        "user": dotprompt.my_prompt.user
    })

If you don't provide a second extension in the prompt file name, the prompt will be considered as a "prompt".

import dotprompt

...
res = gen_ai_client.complete(dotprompt.not_specific.prompt)

The .prompt files can contain comments at the beginning of the file, between /* and */ characters. The comments will be stored in the info attribute of the prompt object and will not be displayed as part of the prompt.

.jprompt

The .jprompt file format is a json file containing multiple prompts with the specified type.

{
    "system": "You are an AI specialized in {speciality}. You are {age} years old.",
    "user": "Tells me about the studies to be come an expert in {speciality}."
}

The jprompt can be commented the same way as the .prompt files.

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

dotprompt-0.1.10.tar.gz (42.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dotprompt-0.1.10-py3-none-any.whl (29.2 kB view details)

Uploaded Python 3

File details

Details for the file dotprompt-0.1.10.tar.gz.

File metadata

  • Download URL: dotprompt-0.1.10.tar.gz
  • Upload date:
  • Size: 42.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for dotprompt-0.1.10.tar.gz
Algorithm Hash digest
SHA256 8b1875cc8411a5b204667f6d930f169914abba64c6ed210eac73f5f066754fd7
MD5 ecfc07214e2a421444876f4a7aeef29a
BLAKE2b-256 6072c37abd54a6df1b0a2b99eae7bd703e78b1e6c431df3f009ef7f4b81b7399

See more details on using hashes here.

File details

Details for the file dotprompt-0.1.10-py3-none-any.whl.

File metadata

  • Download URL: dotprompt-0.1.10-py3-none-any.whl
  • Upload date:
  • Size: 29.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for dotprompt-0.1.10-py3-none-any.whl
Algorithm Hash digest
SHA256 5a2d10fed9bba237971d6b68f04040a018be23e3e56eb32fab165509d3443c01
MD5 6bc28d83c53f5fac85c30be4fe5d2e4b
BLAKE2b-256 ecda41f67d1a05762eedadcdd4f5be92f30ac1f0ca21dda60aa7dba7b642eabb

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