PromptTemplate
meganno_client.prompt.PromptTemplate
The PromptTemplate class represents a prompt template for LLM annotation.
__init__(label_schema, label_names=[], template='', **kwargs)
Init function
Parameters:
Name | Type | Description | Default |
---|---|---|---|
label_schema |
list
|
List of label objects |
required |
label_names |
list
|
List of label names to be used for annotation, by default [] |
[]
|
template |
str
|
Stringified template with input slot, by default '' |
''
|
set_schema(label_schema, label_names)
A helper function to set schema to be used in prompt template.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
label_schema |
[]
|
List of label objects |
required |
label_names |
[]
|
List of label names to be used for annotation, by default all labels |
required |
set_instruction(**kwargs)
Update template's task instruction and/or formatting instruction.
build_template(task_inst, format_inst, f=lambda x: x)
A helper function to build template. Return a stringified prompt template with input slot.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
task_inst |
str
|
Task instruction template. Must include '{name}' and '{options}'. |
required |
format_inst |
str
|
Formatting instruction template. Must include '{format_sample}'. |
required |
f |
function
|
Use color() to decorate string for print, by default lambda x:x |
lambda x: x
|
Returns:
Name | Type | Description |
---|---|---|
template |
str
|
Stringified prompt template with input slot |
set_template(**kwargs)
Update template by updating task instruction and/or formatting instruction.
get_template()
Return the stringified prompt template with input slot.
Returns:
Type | Description |
---|---|
string
|
Stringified prompt template with input slot |
get_prompt(input_str: str, **kwargs)
Return the prompt for a given input.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_str |
str
|
input string to fill input slot |
required |
Returns:
Name | Type | Description |
---|---|---|
prompt |
str
|
a prompt template built with given input string |
preview(records=[])
Open up a widget to modify prompt template and preview final prompt.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
records |
list
|
List of input objects to be used for prompt preview |
[]
|