From ab8c9078f164618a523d20248f9db411f344e473 Mon Sep 17 00:00:00 2001 From: parkervg Date: Fri, 18 Oct 2024 10:36:02 -0400 Subject: [PATCH] `options` can be any Collection, not just a list. But we need to sort it in `to_string()` --- blendsql/ingredients/builtin/map/examples.py | 5 +++-- blendsql/ingredients/builtin/qa/examples.py | 7 ++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/blendsql/ingredients/builtin/map/examples.py b/blendsql/ingredients/builtin/map/examples.py index c15c71c..e2a5df4 100644 --- a/blendsql/ingredients/builtin/map/examples.py +++ b/blendsql/ingredients/builtin/map/examples.py @@ -1,5 +1,6 @@ from attr import attrs, attrib, Factory from typing import Optional, List, Literal, Dict +from collections.abc import Collection from blendsql.ingredients.few_shot import Example @@ -12,7 +13,7 @@ class _MapExample(Example): output_type: Optional[Literal["boolean", "integer", "float", "string"]] = attrib( default=None ) - options: Optional[List[str]] = attrib(default=None) + options: Optional[Collection[str]] = attrib(default=None) example_outputs: Optional[List[str]] = attrib(default=None) values: List[str] = None @@ -30,7 +31,7 @@ def to_string(self, include_values: bool = True) -> str: if self.example_outputs is not None: s += f"Example outputs: {';'.join(self.example_outputs)}\n" if self.options is not None: - s += f"Options: {','.join(self.options)}" + s += f"Options: {','.join(sorted(self.options))}" s += "\n" if include_values: s += "\nValues:\n" diff --git a/blendsql/ingredients/builtin/qa/examples.py b/blendsql/ingredients/builtin/qa/examples.py index 03e9e15..921a7ec 100644 --- a/blendsql/ingredients/builtin/qa/examples.py +++ b/blendsql/ingredients/builtin/qa/examples.py @@ -1,6 +1,7 @@ from attr import attrs, attrib import pandas as pd -from typing import Optional, List, Callable +from typing import Optional, Callable +from collections.abc import Collection from blendsql.ingredients.few_shot import Example @@ -12,13 +13,13 @@ class QAExample(Example): converter=lambda d: pd.DataFrame.from_dict(d) if isinstance(d, dict) else d, default=None, ) - options: Optional[List[str]] = attrib(default=None) + options: Optional[Collection[str]] = attrib(default=None) def to_string(self, context_formatter: Callable[[pd.DataFrame], str]) -> str: s = "" s += f"\n\nQuestion: {self.question}\n" if self.options is not None: - s += f"Options: {', '.join(self.options)}\n" + s += f"Options: {', '.join(sorted(self.options))}\n" if self.context is not None: s += f"Context:\n{context_formatter(self.context)}" s += "\nAnswer: "