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
tools: {
"name": "get_weather",
"description": "Fetches the weather in the given location",
"strict": true,
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The location to get the weather for"
},
"unit": {
"type": ["string", "null"],
"description": "The unit to return the temperature in",
"enum": ["F", "C"]
}
},
"additionalProperties": false,
"required": [
"location", "unit"
]
}
}
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.
You can convert back a prompt to a string
print(str(prompt))
# or store it in a file
with open("task.prompt", "w") as f:
f.write(str(prompt))
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.2.1.tar.gz
(5.4 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.2.1.tar.gz.
File metadata
- Download URL: prompt_parser-0.2.1.tar.gz
- Upload date:
- Size: 5.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.20
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2b5857b58beb9a10d79bb1fba881fb807b6d0d23fc344e12eb9e603e9b4bf473
|
|
| MD5 |
dd5587899438526df5e9a770482df63f
|
|
| BLAKE2b-256 |
aba1d2c3cb30aa3696c213973c30c91ee9f7f22dacac221445c25ecaf53ff7ed
|
File details
Details for the file prompt_parser-0.2.1-py3-none-any.whl.
File metadata
- Download URL: prompt_parser-0.2.1-py3-none-any.whl
- Upload date:
- Size: 6.3 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 |
9b3ad97d40d929bb93dd9489294c53d94daa05decdb52ea140583b87ddc182ff
|
|
| MD5 |
59602e7f2278c17d734149f94e7682e3
|
|
| BLAKE2b-256 |
ab25375fdc37576aa6eff46f32681a34216d86494f804d0a586771e232ee2ed5
|