Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions mellea/stdlib/funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ async def _act(
"Must provide a SamplingStrategy when return_sampling_results==True"
)

# if there is no reason to sample, just generate from the context.
if strategy is None or requirements is None or len(requirements) == 0:
if strategy is None and requirements is not None:
if strategy is None:
# Only use the strategy if one is provided. Add a warning if requirements were passed in though.
if requirements is not None and len(requirements) >= 0:
FancyLogger.get_logger().warning(
"Calling the function with NO strategy BUT requirements. No requirement is being checked!"
)
Expand Down Expand Up @@ -394,6 +394,13 @@ async def _validate(
# Turn a solitary requirement in to a list of requirements, and then reqify if needed.
reqs = [reqs] if not isinstance(reqs, list) else reqs
reqs = [Requirement(req) if type(req) is str else req for req in reqs]

if len(reqs) == 0:
FancyLogger().get_logger().warning(
"Calling validate with no requirements. This is a no-op."
)
return []

if output is None:
validation_target_ctx = context
else:
Expand Down
4 changes: 2 additions & 2 deletions mellea/stdlib/sampling/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ async def sample(
action: Component,
context: Context,
backend: Backend,
requirements: list[Requirement],
requirements: list[Requirement] | None,
*,
validation_ctx: Context | None = None,
format: type[BaseModelSubclass] | None = None,
Expand Down Expand Up @@ -123,7 +123,7 @@ async def sample(
show_progress = show_progress and flog.getEffectiveLevel() <= FancyLogger.INFO

reqs = []
# global requirements supersede local requirements (global requiremenst can be defined by user)
# global requirements supersede local requirements (global requirements can be defined by user)
# Todo: re-evaluate if this makes sense
if self.requirements is not None:
reqs += self.requirements
Expand Down
2 changes: 1 addition & 1 deletion mellea/stdlib/sampling/best_of_n.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ async def sample(
action: Component,
context: Context,
backend: Backend,
requirements: list[Requirement],
requirements: list[Requirement] | None,
*,
validation_ctx: Context | None = None,
format: type[BaseModelSubclass] | None = None,
Expand Down
2 changes: 1 addition & 1 deletion mellea/stdlib/sampling/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ async def sample(
action: Component,
context: Context,
backend: Backend,
requirements: list[Requirement],
requirements: list[Requirement] | None,
*,
validation_ctx: Context | None = None,
format: type[BaseModelSubclass] | None = None,
Expand Down
2 changes: 1 addition & 1 deletion test/stdlib_basics/test_vision_ollama.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def test_image_block_construction_from_pil(pil_image: Image.Image):

def test_image_block_in_instruction(m_session: MelleaSession, pil_image: Image.Image, gh_run: int):
image_block = ImageBlock.from_pil_image(pil_image)
instr = m_session.instruct("Is this image mainly blue? Answer yes or no.", images=[image_block])
instr = m_session.instruct("Is this image mainly blue? Answer yes or no.", images=[image_block], strategy=None)
assert isinstance(instr, ModelOutputThunk)

# if not on GH
Expand Down
2 changes: 1 addition & 1 deletion test/stdlib_basics/test_vision_openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def test_image_block_construction_from_pil(pil_image: Image.Image):

def test_image_block_in_instruction(m_session: MelleaSession, pil_image: Image.Image, gh_run: int):
image_block = ImageBlock.from_pil_image(pil_image)
instr = m_session.instruct("Is this image mainly blue? Answer yes or no.", images=[image_block])
instr = m_session.instruct("Is this image mainly blue? Answer yes or no.", images=[image_block], strategy=None)
assert isinstance(instr, ModelOutputThunk)

# if not on GH
Expand Down
Loading