Skip to content

Commit

Permalink
options can be any Collection, not just a list. But we need to sort…
Browse files Browse the repository at this point in the history
… it in `to_string()`
  • Loading branch information
parkervg committed Oct 18, 2024
1 parent 880c2b1 commit ab8c907
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
5 changes: 3 additions & 2 deletions blendsql/ingredients/builtin/map/examples.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
Expand All @@ -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"
Expand Down
7 changes: 4 additions & 3 deletions blendsql/ingredients/builtin/qa/examples.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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: "
Expand Down

0 comments on commit ab8c907

Please sign in to comment.