Source code for langchain_core.example_selectors.base
"""Interface for selecting examples to include in prompts."""fromabcimportABC,abstractmethodfromtypingimportAny,Dict,Listfromlangchain_core.runnablesimportrun_in_executor
[docs]classBaseExampleSelector(ABC):"""Interface for selecting examples to include in prompts."""
[docs]@abstractmethoddefadd_example(self,example:Dict[str,str])->Any:"""Add new example to store. Args: example: A dictionary with keys as input variables and values as their values."""
[docs]asyncdefaadd_example(self,example:Dict[str,str])->Any:"""Async add new example to store. Args: example: A dictionary with keys as input variables and values as their values."""returnawaitrun_in_executor(None,self.add_example,example)
[docs]@abstractmethoddefselect_examples(self,input_variables:Dict[str,str])->List[dict]:"""Select which examples to use based on the inputs. Args: input_variables: A dictionary with keys as input variables and values as their values."""
[docs]asyncdefaselect_examples(self,input_variables:Dict[str,str])->List[dict]:"""Async select which examples to use based on the inputs. Args: input_variables: A dictionary with keys as input variables and values as their values."""returnawaitrun_in_executor(None,self.select_examples,input_variables)