promptmeteo.selector package#
Submodules#
promptmeteo.selector.base module#
- class promptmeteo.selector.base.BaseSelector(language: str, embeddings: Embeddings, selector_k: int, selector_algorithm: str)#
Bases:
ABC
Base Selector Interface
- SELECTOR = None#
- load_example_selector(model_path: str, **kwargs) Self #
Load a vectorstore database from a disk file
- property template: str#
Selector Template
- property vectorstore#
Selector Vectorstore.
- class promptmeteo.selector.base.BaseSelectorSupervised(language: str, embeddings: Embeddings, selector_k: int, selector_algorithm: str)#
Bases:
BaseSelector
- run(sample: str) FewShotPromptTemplate #
Creates the FewShotPromptTemplate from the samples of the vectorstore.
- train(examples: List[str], annotations: List[str]) Self #
Creates the vectorstor with the training samples.
- class promptmeteo.selector.base.BaseSelectorUnsupervised(language: str, embeddings: Embeddings, selector_k: int, selector_algorithm: str)#
Bases:
BaseSelector
- run() FewShotPromptTemplate #
Creates the FewShotPromptTemplate from the samples of the vectorstore.
- train(examples: List[str], annotations: List[str] | None) Self #
Creates the vectorstore with the training samples.
- class promptmeteo.selector.base.SelectorAlgorithms(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)#
Bases:
str
,Enum
Enum with the avaialable selector algorithms.
- RELEVANCE: str = 'relevance'#
- SIMILARITY: str = 'similarity'#
- SIMILARITY_CLASS_BALANCED: str = 'similarity_class_balanced'#
promptmeteo.selector.custom_selectors module#
Custom selectors
- class promptmeteo.selector.custom_selectors.BalancedSemanticSamplesSelector(*, vectorstore: VectorStore, k: int = 6, example_keys: List[str] | None = None, input_keys: List[str] | None = None, vectorstore_kwargs: Dict[str, Any] | None = None, class_list: List[str], class_key: str)#
Bases:
BaseExampleSelector
,BaseModel
Example selector that selects examples based on SemanticSimilarity in a balanced way.
- add_example(example: Dict[str, str]) str #
Add new example to vectorstore.
- class_key: str#
- class_list: List[str]#
element of examples metadata which contains the class
- example_keys: List[str] | None#
Optional keys to filter examples to.
- classmethod from_examples(examples: List[dict], class_list: List[str], class_key: str, embeddings: Embeddings, vectorstore_cls: Type[VectorStore], k: int = 6, input_keys: List[str] | None = None, **vectorstore_cls_kwargs: Any)#
Create k-shot example selector using example list and embeddings.
Reshuffles examples dynamically based on query similarity.
- Parameters:
examples – List of examples to use in the prompt.
class_list – list of classes of the classification problem
class_key – key which refers to category field in the example dictionary
embeddings – An initialized embedding API interface, e.g. OpenAIEmbeddings().
vectorstore_cls – A vector store DB interface class, e.g. FAISS.
input_keys – If provided, the search is based on the input variables instead of all variables.
vectorstore_cls_kwargs – optional kwargs containing url for vector store
- Returns:
The ExampleSelector instantiated, backed by a vector store.
- input_keys: List[str] | None#
Optional keys to filter input to. If provided, the search is based on the input variables instead of all variables.
- k: int#
Number of examples to select per class.
- select_examples(input_variables: Dict[str, str]) List[dict] #
Select which examples to use based on semantic similarity.
- vectorstore: VectorStore#
Vectorstore
- vectorstore_kwargs: Dict[str, Any] | None#
Extra arguments passed to similarity_search function of the vectorstore.
- promptmeteo.selector.custom_selectors.sorted_values(values: Dict[str, str]) List[Any] #
Return a list of values in dict sorted by key.
Module contents#
- class promptmeteo.selector.SelectorFactory#
Bases:
object
Factory of Selectors
- classmethod factory_method(language: str, embeddings: Embeddings, selector_k: int, selector_type: str, selector_algorithm: str) BaseSelector #
Returns and instance of a BaseSelector object depending on the selector_algorithm.