Add add_example method to all ExampleSelector classes, with tests (#178)

Also updated docs, and noticed an issue with the add_texts method on
VectorStores that I had missed before -- the metadatas arg should be
required to match the classmethod which initializes the VectorStores
(the add_example methods break otherwise in the ExampleSelectors)
This commit is contained in:
Samantha Whitmore
2022-11-23 16:12:47 -05:00
committed by GitHub
parent 780ef84cf0
commit 09f301cd38
8 changed files with 119 additions and 14 deletions

View File

@@ -29,6 +29,15 @@ def test_dynamic_prompt_valid(selector: LengthBasedExampleSelector) -> None:
assert output == EXAMPLES
def test_dynamic_prompt_add_example(selector: LengthBasedExampleSelector) -> None:
"""Test dynamic prompt can add an example."""
new_example = {"question": "Question: what are you?\nAnswer: bar"}
selector.add_example(new_example)
short_question = "Short question?"
output = selector.select_examples({"question": short_question})
assert output == EXAMPLES + [new_example]
def test_dynamic_prompt_trims_one_example(selector: LengthBasedExampleSelector) -> None:
"""Test dynamic prompt can trim one example."""
long_question = """I am writing a really long question,