Skip to main content

A simple Python library for parsing LLM prompts.

Project description

Prompt Parser

GitHub LICENSE Mounthly Download latest version supported python version

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


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.7.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

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

prompt_parser-0.1.7-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file prompt_parser-0.1.7.tar.gz.

File metadata

  • Download URL: prompt_parser-0.1.7.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.20

File hashes

Hashes for prompt_parser-0.1.7.tar.gz
Algorithm Hash digest
SHA256 9ccc9bd7c063a6c8f7c4850309551f136dc0bab1ba2a297225186d2e9b1b1a3c
MD5 2ec087f29feed8c9d4c1ef70a4942ad2
BLAKE2b-256 c24725c8ecf0fe2c96dd850a0420bc0741ef8418edf4404b0332b1e8b48ae792

See more details on using hashes here.

File details

Details for the file prompt_parser-0.1.7-py3-none-any.whl.

File metadata

  • Download URL: prompt_parser-0.1.7-py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.20

File hashes

Hashes for prompt_parser-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 aaf1f5179fc470621db47efd623e9bd9c4a0ef4669ced512b466d5715589b854
MD5 856148a404d19fda282fe0553120533f
BLAKE2b-256 48e32b67e99c99d1f0e65d6d8d949f0709a8a16837ad7dddfcc76a8b1114d8b4

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