langchain_core.example_selectors.length_based
.LengthBasedExampleSelector¶
- class langchain_core.example_selectors.length_based.LengthBasedExampleSelector[source]¶
Bases:
BaseExampleSelector
,BaseModel
Select examples based on length.
Create a new model by parsing and validating input data from keyword arguments.
Raises ValidationError if the input data cannot be parsed to form a valid model.
- param example_prompt: PromptTemplate [Required]¶
Prompt template used to format the examples.
- param example_text_lengths: List[int] = []¶
Length of each example.
- param examples: List[dict] [Required]¶
A list of the examples that the prompt template expects.
- param get_text_length: Callable[[str], int] = <function _get_length_based>¶
Function to measure prompt length. Defaults to word count.
- param max_length: int = 2048¶
Max length for the prompt, beyond which examples are cut.
- async aadd_example(example: Dict[str, str]) None [source]¶
Async add new example to list.
- Parameters
example (Dict[str, str]) – A dictionary with keys as input variables and values as their values.
- Return type
None
- add_example(example: Dict[str, str]) None [source]¶
Add new example to list.
- Parameters
example (Dict[str, str]) – A dictionary with keys as input variables and values as their values.
- Return type
None
- async aselect_examples(input_variables: Dict[str, str]) List[dict] [source]¶
Async select which examples to use based on the input lengths.
- Parameters
input_variables (Dict[str, str]) – A dictionary with keys as input variables and values as their values.
- Returns
A list of examples to include in the prompt.
- Return type
List[dict]
- select_examples(input_variables: Dict[str, str]) List[dict] [source]¶
Select which examples to use based on the input lengths.
- Parameters
input_variables (Dict[str, str]) – A dictionary with keys as input variables and values as their values.
- Returns
A list of examples to include in the prompt.
- Return type
List[dict]