Add your description here
Project description
doprompt-py
DoPrompt is a python package to parse and execute dotprompt files - a filetype created by Google to store prompts outside of the code itself.
This library exists to create vendor independent tooling for a better way to store and interact with prompts.
Please check out the visual studio code extension to easily play around with your prompts without ripping them out of your code.
Example
- Install doprompt
pip install doprompt
- Create a
chatbot.promptfile
---
model: openai/gpt-4o
config:
temperature: 0.9
input:
schema:
userQuestion: string
---
{{role "system"}}
You are a helpful AI assistant that really loves to talk about food. Try to work
food items into all of your conversations.
{{role "user"}}
{{userQuestion}}
- Execute the prompt You can use our completion API to automatically dispatch the prompt to the right vendor library and pass in the parameters you configured:
import doprompt
prompt = DoPrompt("./chatbot.prompt")
print(prompt.complete({'userQuestion': 'Which way is the library?'})
Alternatively if you need custom APIs, settings or vendors you can also manually pass down any parameters. The following snippet results in equivalent behaviour
import doprompt
from openai import OpenAI
prompt = DoPrompt("./chatbot.prompt")
openai = OpenAI()
messages = prompt.get_messages(values={
'userQuestion': 'What is the capital of France?',
})
client = OpenAI()
completion = client.chat.completions.create(
messages=prompt.get_messages(vals),
model=prompt.model_name,
temperature=prompt.get_config('temperature'),
)
print(completion.choices[0].message.content)
Backgorund
Hardcoding prompt is a very constraining solution, since prompts often need very interactive development which is hard once they're embedded in code. The alterantive would be to use a prompt management platform, which create an additional dependency and point of failure, whilst siloing away your prompts from the parts they are actually very integrated into.
Separating them into their own file keeps them close to the code while allowing additional tooling to help you interactively develop them.
Supported features
- handlebars templating
- config settings
- roles
- schema validation
- media support
- alternative templating languages
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file doprompt-0.1.2.tar.gz.
File metadata
- Download URL: doprompt-0.1.2.tar.gz
- Upload date:
- Size: 4.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.4.29
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8998e53b3131f5e1540f0bacdbd75204dcb087a48db1410169956b3c3da9d35d
|
|
| MD5 |
fe2f9d339b4d07576d3ec42b94571c65
|
|
| BLAKE2b-256 |
bcd2adee307cfce391cb55f4bc2cffed75739631c9c5e8f096b3e2c100a9567b
|
File details
Details for the file doprompt-0.1.2-py3-none-any.whl.
File metadata
- Download URL: doprompt-0.1.2-py3-none-any.whl
- Upload date:
- Size: 5.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.4.29
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
184f7fe43d947f1cd2ebf727fd362ab1670d11de78ef575f1c30e269d5db292c
|
|
| MD5 |
51a4137a11db837ad7b58e48a72eefe6
|
|
| BLAKE2b-256 |
af6a6df6333dc39b041ab9a37454cf416a8078a87310444477e07aabd66aee8b
|