Skip to content

Commit

Permalink
Raising IngredientException on LLM ingredients if model is None
Browse files Browse the repository at this point in the history
  • Loading branch information
parkervg committed Jun 21, 2024
1 parent aa83a8c commit 72a6c16
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions blendsql/ingredients/builtin/map/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from blendsql.ingredients.ingredient import MapIngredient
from blendsql._program import Program
from blendsql import generate
from blendsql._exceptions import IngredientException


class MapProgram(Program):
Expand Down Expand Up @@ -157,6 +158,10 @@ def run(
Returns:
Iterable[Any] containing the output of the Model for each value.
"""
if model is None:
raise IngredientException(
"LLMMap requires a `Model` object, but nothing was passed!\nMost likely you forgot to set the `default_model` argument in `blend()`"
)
# Unpack default kwargs
tablename, colname = self.unpack_default_kwargs(**kwargs)
# Remote endpoints can't use patterns
Expand Down
5 changes: 5 additions & 0 deletions blendsql/ingredients/builtin/qa/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from blendsql.ingredients.ingredient import QAIngredient
from blendsql.db.utils import single_quote_escape
from blendsql import generate
from blendsql._exceptions import IngredientException


class QAProgram(Program):
Expand Down Expand Up @@ -91,6 +92,10 @@ def run(
long_answer: bool = False,
**kwargs,
) -> Union[str, int, float]:
if model is None:
raise IngredientException(
"LLMQA requires a `Model` object, but nothing was passed!\nMost likely you forgot to set the `default_model` argument in `blend()`"
)
if context is not None:
if value_limit is not None:
context = context.iloc[:value_limit]
Expand Down
5 changes: 5 additions & 0 deletions blendsql/ingredients/builtin/validate/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from blendsql._program import Program
from blendsql.ingredients.ingredient import QAIngredient
from blendsql import generate
from blendsql._exceptions import IngredientException


class ValidateProgram(Program):
Expand Down Expand Up @@ -38,6 +39,10 @@ def run(
long_answer: bool = False,
**kwargs,
) -> Union[str, int, float]:
if model is None:
raise IngredientException(
"LLMValidate requires a `Model` object, but nothing was passed!\nMost likely you forgot to set the `default_model` argument in `blend()`"
)
if context is not None:
if value_limit is not None:
context = context.iloc[:value_limit]
Expand Down
4 changes: 4 additions & 0 deletions blendsql/ingredients/builtin/vqa/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ class ImageCaption(MapIngredient):

def run(self, model: Model, values: List[bytes], **kwargs):
"""Generates a caption for all byte images passed to it."""
if model is None:
raise IngredientException(
"ImageCaption requires a `Model` object, but nothing was passed!\nMost likely you forgot to set the `default_model` argument in `blend()`"
)
if not all(isinstance(value, bytes) for value in values):
raise IngredientException(
f"All values must be 'byte' type for ImageCaption!"
Expand Down

0 comments on commit 72a6c16

Please sign in to comment.