Better error when running chain without any args (#4294)

Today, when running a chain without any arguments, the raised ValueError
incorrectly specifies that user provided "both positional arguments and
keyword arguments".

This PR adds a more accurate error in that case.
This commit is contained in:
Lior Neudorfer 2023-05-08 07:11:51 +03:00 committed by GitHub
parent edcd171535
commit 65c95f9fb2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -238,6 +238,12 @@ class Chain(BaseModel, ABC):
if kwargs and not args:
return self(kwargs, callbacks=callbacks)[self.output_keys[0]]
if not kwargs and not args:
raise ValueError(
"`run` supported with either positional arguments or keyword arguments,"
" but none were provided."
)
raise ValueError(
f"`run` supported with either positional arguments or keyword arguments"
f" but not both. Got args: {args} and kwargs: {kwargs}."