-
Notifications
You must be signed in to change notification settings - Fork 161
Description
Currently cocoindex function can only be called in chain style (arg0.transform(FunctionSpec(...), remaining_args...)
). It's convenient for many cases, but there're situations that not fits into this. e.g. in Python we may have a function like:
def extract_from_llm(text: str = None, image: bytes = None):
...
If the first argument text
is required, text
can acts as a self
(this is the current chain-style transform that we support). But here both text
and image
are optional. There's no clear equivalence in chain style.
For the non-chain-style function calls, two options in my mind for now:
-
FunctionSpec(...).transform(args...)
orFunctionSpec(...).call(args...)
. For standalone function, it'scustom_fn.transform(args...)
orcustom_fn.transform.call(args...)
- More explicit
- But more verbose, and
FunctionSpec
cannot havecall
field
-
FunctionSpec(...)(args...)
. For standalone function, it'scustom_fn(args...)
- More concise, no restriction
- But two adjacent
(...)(...)
looks a little bit uncommon - For standalone function, it's probably hard to avoid mypy raising error (mypy will assume
custom_fn
takes values as input, instead ofDataSlice
)
Would like to hear some feedback about the desired style before proceeds.
More context: #653 (comment)
❤️ Contributors, please refer to 📙Contributing Guide.
Unless the PR can be sent immediately (e.g. just a few lines of code), we recommend you to leave a comment on the issue like I'm working on it
or Can I work on this issue?
to avoid duplicating work. Our Discord server is always open and friendly.