A simple Python library for parsing LLM prompts.
Project description
Prompt Parser
A simple Python library for parsing LLM prompts.
Usage
from prompt_parser import Prompt
prompt = Prompt.parse("""
---
temperature: 0.5
top_p: 0.5
top_k: 50
max_tokens: 4096
provider: openai
model: gpt-4
endpoint: chat
unknown: blablah
---
<system>
Hi from system
</system>
<user>
Hi from user {custom}
</user>
<assistant>
Hi from assistant
</assistant>
""")
# getters
prompt.system # Hi from system
# or
prompt.system_forced # "Hi from system" -> will throw an error if not present
prompt.user # Hi from user {custom}
# or
prompt.user_forced # "Hi from user {custom}" -> will throw an error if not present
prompt.assistant # Hi from assistant
# or
prompt.assistant_forced # "Hi from assistant" -> will throw an error if not present
prompt.format_user(custom="Alex") # "Hi from user Alex"
# check also `format_system` and `format_assistant`
# access the attributes
prompt.attributes.temperature # 0.5
prompt.attributes.top_p # 0.5
prompt.attributes.top_k # 50
prompt.attributes.provider # openai
prompt.attributes.model # gpt-4
prompt.attributes.endpoint # chat
prompt.attributes.max_tokens # 4096
prompt.attributes["unknown"] # blahblah
You can also use the Prompt.parse_from_file(path) method to parse a prompt file given its path.
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
prompt_parser-0.1.6.tar.gz
(4.1 kB
view details)
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 prompt_parser-0.1.6.tar.gz.
File metadata
- Download URL: prompt_parser-0.1.6.tar.gz
- Upload date:
- Size: 4.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.20
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
69b50b112193f9a61e369034d403dea2636dec0b6c0e759705f80fd8dffcbf62
|
|
| MD5 |
78a5bd493f0c34a3140a21ab6f193a83
|
|
| BLAKE2b-256 |
35864d5a98b12577b60774f762d6d83ce377afdcba559ba2e7a11288bed8fbd9
|
File details
Details for the file prompt_parser-0.1.6-py3-none-any.whl.
File metadata
- Download URL: prompt_parser-0.1.6-py3-none-any.whl
- Upload date:
- Size: 4.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.20
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9bfc4a08c30611863e17414921ca26fcc803ea2142e0e3598d6516b07d834ae9
|
|
| MD5 |
c61fab312fce970ffff5c878e592a815
|
|
| BLAKE2b-256 |
2bd391acc3d01354def027777130039fe0b1dbd002b7d29f52f1d2a1277ab205
|