New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow calls to batch() with 0 length arrays #10627
Conversation
This can happen if eg the input to batch is a list generated dynamically, where a 0-length list might be a valid use case
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Ignored Deployment
|
@@ -97,8 +97,8 @@ def get_config_list( | |||
Helper method to get a list of configs from a single config or a list of | |||
configs, useful for subclasses overriding batch() or abatch(). | |||
""" | |||
if length < 1: | |||
raise ValueError(f"length must be >= 1, but got {length}") | |||
if length < 0: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think additional code is needed in default batch implementation since it assumes that the list of configs cannot be empty
"""
configs = get_config_list(config, len(inputs))
def invoke(input: Input, config: RunnableConfig) -> Union[Output, Exception]:
if return_exceptions:
try:
return self.invoke(input, config, **kwargs)
except Exception as e:
return e
else:
return self.invoke(input, config, **kwargs)
# If there's only one input, don't bother with the executor
if len(inputs) == 1:
return cast(List[Output], [invoke(inputs[0], configs[0])])
with get_executor_for_config(configs[0]) as executor:
return cast(List[Output], list(executor.map(invoke, inputs, configs)))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point! updated
.batch([]) won't produce any traces on langsmith |
This can happen if eg the input to batch is a list generated dynamically, where a 0-length list might be a valid use case