PyPrompt
Installation
pip install pyprompt
Usage
from pyprompt import *
prompt = PromptElement()
Properties
For pruning (removing text when you have more tokens than budgeted), the priority, pass_priority, and reserve
fields are used.
priority: This determines the order that elements are pruned. The elements are pruned from the lowest priority to highest, and the default value is max priority.pass_priority: Normally, priority is compared amongst sibling elements. Ifpass_priorityisTrue, then that element's children are compared to its siblings. The default value isFalse.reserve: This keyword, when set, reserves a specified number of tokens from the total budget of the prompt. It can be set as anint(e.g. 60, which would reserve 60 tokens) or afloat(e.g. 1/3, which would reserve one-third of the total token budget). When pruning, this element can be pruned down to its reserve amount, but not past it. The default value isNone.
For growing (adding more text when the budget allows it), the grow_ratio and grow_callback are used. For an element
to grow into the unused budget, it must have a grow_callback.
grow_ratio: This determines what portion of the unused budget is given to this element. The portion ofgrow_ratioto the sum of allgrow_ratiosdictates how many tokens from the unused budget are allocated to this element. For example, if three elements havegrow_ratiosof 1, 2, and 3 and the unused token budget is 60 tokens, then they will get 10, 20, and 30 tokens to grow, respectively. Thegrow_ratiocan be anintorfloat, and the default value is1.grow_callback: This is a function that creates a newTokenMapfor aPromptElementthat uses up more of the budget, if possible. The function's signature is as follows:- Inputs:
PromptElement: The element to grow.encoding_func: The function to encode strings to tokens.decoding_func: The function to decode tokens to strings.Any | None: The state of the function (Nonethe first time the function is called, then the output of the previous call).
- Outputs:
TokenMap | None: TheTokenMapof thePromptElementafter growing, orNoneif it cannot grow anymore.Any | None: The state of the function, used in the next grow call.
- Inputs:
- It is ill-advised to have elements with
grow_callbackas descendants of another element withgrow_callback.grow_callbackshould only be set on leaf nodes.
Metadata
Release files for pyprompt 0.3.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pyprompt-0.3.5.tar.gz | 8.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pyprompt-0.3.5-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 19.6 kB
Release files / pyprompt-0.3.5.tar.gz
| Download URL | pyprompt-0.3.5.tar.gz |
|---|---|
| Size | 8.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2df2d59f7a45dad5769e4d091e823020297d94d4d237a120d2a48b4b8185a3ed
|
|
BLAKE2b-256 checksum How to use checksums |
72d093a8a87cdd4a0207157722b7f921b9d53bb62a0a4a04f3ea6abf9f56aff5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.10.16
|
Release files / pyprompt-0.3.5-py3-none-any.whl
| Download URL | pyprompt-0.3.5-py3-none-any.whl |
|---|---|
| Size | 11.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7de583dcdc1437ccf545a9d2e58628a2e8f54d6b1d3f598f7246a3f89a9088eb
|
|
BLAKE2b-256 checksum How to use checksums |
186a7069548029d098ebd664f3c55e40f8c21dced6a5b847f8c5e9e685d2d793
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.10.16
|