Prompt#
dbally.prompt.template.PromptTemplate
#
PromptTemplate(chat: ChatFormat, *, json_mode: bool = False, response_parser: Callable = lambda x: x)
Bases: Generic[PromptFormatT]
Class for prompt templates.
Constructs a new PromptTemplate instance.
PARAMETER | DESCRIPTION |
---|---|
chat |
Chat-formatted conversation template.
TYPE:
|
json_mode |
Whether to enforce JSON response from LLM.
TYPE:
|
response_parser |
Function parsing the LLM response into the desired format.
TYPE:
|
Source code in src/dbally/prompt/template.py
format_prompt
#
Applies formatting to the prompt template chat contents.
PARAMETER | DESCRIPTION |
---|---|
prompt_format |
Format to be applied to the prompt.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
PromptTemplate with formatted chat contents. |
Source code in src/dbally/prompt/template.py
set_system_message
#
Sets a system message to the template prompt.
PARAMETER | DESCRIPTION |
---|---|
content |
Message to be added.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
PromptTemplate with appended system message. |
Source code in src/dbally/prompt/template.py
add_user_message
#
Add a user message to the template prompt.
PARAMETER | DESCRIPTION |
---|---|
content |
Message to be added.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
PromptTemplate with appended user message. |
Source code in src/dbally/prompt/template.py
add_assistant_message
#
Add an assistant message to the template prompt.
PARAMETER | DESCRIPTION |
---|---|
content |
Message to be added.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
PromptTemplate with appended assistant message. |
Source code in src/dbally/prompt/template.py
add_few_shot_message
#
add_few_shot_message(example: FewShotExample) -> Self
Add a few-shot message to the template prompt.
PARAMETER | DESCRIPTION |
---|---|
example |
Few-shot example to be added.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
PromptTemplate with appended few-shot message. |
RAISES | DESCRIPTION |
---|---|
PromptTemplateError
|
if the template is empty. |
Source code in src/dbally/prompt/template.py
clear_few_shot_messages
#
Removes all few-shot messages from the template prompt.
RETURNS | DESCRIPTION |
---|---|
Self
|
PromptTemplate with few-shot messages removed. |
Source code in src/dbally/prompt/template.py
dbally.prompt.template.PromptFormat
#
PromptFormat(examples: Optional[List[FewShotExample]] = None)
Generic format for prompts allowing to inject few shot examples into the conversation.
Constructs a new PromptFormat instance.
PARAMETER | DESCRIPTION |
---|---|
examples |
List of examples to be injected into the conversation.
TYPE:
|
Source code in src/dbally/prompt/template.py
dbally.prompt.elements.FewShotExample
#
A question:answer representation for few-shot prompting
PARAMETER | DESCRIPTION |
---|---|
question |
sample question
TYPE:
|
answer_expr |
it can be either a stringified expression or a lambda for greater safety and code completions.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
ValueError
|
If answer_expr is not a correct type. |