Skip to content

Commit

Permalink
format_tuple to db/utils.py
Browse files Browse the repository at this point in the history
  • Loading branch information
parkervg committed Oct 22, 2024
1 parent 9885886 commit 816d466
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
4 changes: 4 additions & 0 deletions blendsql/db/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ def escape(s):
return single_quote_escape(double_quote_escape(s))


def format_tuple(value: tuple):
return "(" + ",".join(repr(v) for v in value) + ")"


def select_all_from_table_query(tablename: str) -> str:
return f'SELECT * FROM "{double_quote_escape(tablename)}";'

Expand Down
10 changes: 7 additions & 3 deletions blendsql/ingredients/ingredient.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
IngredientType,
)
from ..db import Database
from ..db.utils import select_all_from_table_query
from ..db.utils import select_all_from_table_query, format_tuple
from .utils import unpack_options
from .few_shot import Example
from .utils import partialclass
Expand Down Expand Up @@ -543,7 +543,7 @@ def run(self, model: Model, context: pd.DataFrame, **kwargs) -> str:
'''

ingredient_type: str = IngredientType.QA.value
allowed_output_types: Tuple[Type] = (Union[str, int, float],)
allowed_output_types: Tuple[Type] = (Union[str, int, float, tuple],)

def __call__(
self,
Expand Down Expand Up @@ -588,7 +588,11 @@ def __call__(
self.num_values_passed += len(subtable) if subtable is not None else 0
kwargs[IngredientKwarg.CONTEXT] = subtable
kwargs[IngredientKwarg.QUESTION] = question
response: Union[str, int, float] = self._run(*args, **self.__dict__ | kwargs)
response: Union[str, int, float, tuple] = self._run(
*args, **self.__dict__ | kwargs
)
if isinstance(response, tuple):
response = format_tuple(response)
return response

@abstractmethod
Expand Down

0 comments on commit 816d466

Please sign in to comment.