Formatron v0.4.9
Formatron empowers everyone to control the output format of language models with minimal overhead.
|
An abstract Formatter that enforces a format on the string generated by a language model. More...
Public Member Functions | |
accept_token (self, int token_id) | |
Accept a token from the language model. | |
None | accept_bytes (self, bytes _bytes) |
Accept a bytes object from the language model. | |
None | compute_allowed_tokens (self) |
Compute the allowed tokens based on the current state. | |
typing.Any | mask_logits (self, logits) |
Mask the logits based on the current state. | |
typing.Sequence[int] | get_allowed_tokens_since_last_computation (self) |
Get the allowed tokens since the last computation(in other words, the last call to compute_allowed_tokens ). | |
bool | is_completed (self) |
Check if the generated string satisfies the format and hence the generation is completed. | |
dict[str, typing.Any|None] | captures (self) |
None | reset (self) |
Reset the formatter to the initial state. | |
Protected Member Functions | |
None | _on_completion (self, str generated_output) |
Perform actions when the generation is completed. | |
An abstract Formatter that enforces a format on the string generated by a language model.
Definition at line 24 of file formatter.py.
|
protected |
Perform actions when the generation is completed.
Reimplemented in formatron.formatter.Formatter.
Definition at line 80 of file formatter.py.
None formatron.formatter.FormatterBase.accept_bytes | ( | self, | |
bytes | _bytes ) |
Accept a bytes object from the language model.
_bytes | The bytes object. |
Reimplemented in formatron.formatter.Formatter.
Definition at line 42 of file formatter.py.
formatron.formatter.FormatterBase.accept_token | ( | self, | |
int | token_id ) |
Accept a token from the language model.
token_id | The token ID. |
Reimplemented in formatron.formatter.Formatter.
Definition at line 34 of file formatter.py.
dict[str, typing.Any|None] formatron.formatter.FormatterBase.captures | ( | self | ) |
Reimplemented in formatron.formatter.Formatter.
Definition at line 98 of file formatter.py.
None formatron.formatter.FormatterBase.compute_allowed_tokens | ( | self | ) |
Compute the allowed tokens based on the current state.
Reimplemented in formatron.formatter.Formatter.
Definition at line 48 of file formatter.py.
typing.Sequence[int] formatron.formatter.FormatterBase.get_allowed_tokens_since_last_computation | ( | self | ) |
Get the allowed tokens since the last computation(in other words, the last call to compute_allowed_tokens
).
Reimplemented in formatron.formatter.Formatter.
Definition at line 66 of file formatter.py.
bool formatron.formatter.FormatterBase.is_completed | ( | self | ) |
Check if the generated string satisfies the format and hence the generation is completed.
Reimplemented in formatron.formatter.Formatter.
Definition at line 72 of file formatter.py.
typing.Any formatron.formatter.FormatterBase.mask_logits | ( | self, | |
logits ) |
Mask the logits based on the current state.
logits | The logits to mask. |
Reimplemented in formatron.formatter.Formatter.
Definition at line 58 of file formatter.py.
None formatron.formatter.FormatterBase.reset | ( | self | ) |
Reset the formatter to the initial state.
Reimplemented in formatron.formatter.Formatter.
Definition at line 104 of file formatter.py.