Skip to content

Build AI methods with your coding agent, then run them anywhere: as an MCP for chatbots, as a webapp for people, or via API for your software.

Tweak to make_optional_batch_params to raise error if it's inconsistent

Louis Choquelb96a4a84b5a8
diff --git a/pipelex/core/pipes/pipe_run_params.py b/pipelex/core/pipes/pipe_run_params.py
index 037c2b501..34c0ac93e 100644
--- a/pipelex/core/pipes/pipe_run_params.py
+++ b/pipelex/core/pipes/pipe_run_params.py
@@ -6,6 +6,7 @@ from pydantic import BaseModel, Field, field_validator
from pipelex import log
from pipelex.core.memory.working_memory import BATCH_ITEM_STUFF_NAME, MAIN_STUFF_NAME
+from pipelex.exceptions import BatchParamsError
from pipelex.types import Self, StrEnum
@@ -178,16 +179,19 @@ class BatchParams(BaseModel):
def make_optional_batch_params(
cls,
input_list_name: str | None,
- input_item_name: str | None = None,
+ input_item_name: str | None,
) -> BatchParams | None:
- the_batch_params: BatchParams | None = None
if input_list_name:
input_item_stuff_name = input_item_name or BATCH_ITEM_STUFF_NAME
- the_batch_params = BatchParams(
+ return BatchParams(
input_list_stuff_name=input_list_name,
input_item_stuff_name=input_item_stuff_name,
)
- return the_batch_params
+ elif input_item_name:
+ msg = "input_item_name is required when input_list_name is not provided"
+ raise BatchParamsError(msg)
+ else:
+ return None
@classmethod
def make_default(cls) -> BatchParams:
diff --git a/pipelex/exceptions.py b/pipelex/exceptions.py
index f16a8b59d..c8dfbdb45 100644
--- a/pipelex/exceptions.py
+++ b/pipelex/exceptions.py
@@ -221,6 +221,10 @@ class DryRunError(PipeExecutionError):
super().__init__(message)
+class BatchParamsError(PipelexError):
+ pass
+
+
class PipeConditionError(PipelexError):
pass