Skip to content

[FEATURE] Support non-chain-style cocoindex function call #654

@badmonster0

Description

@badmonster0

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:

  1. FunctionSpec(...).transform(args...) or FunctionSpec(...).call(args...). For standalone function, it's custom_fn.transform(args...) or custom_fn.transform.call(args...)

    • More explicit
    • But more verbose, and FunctionSpec cannot have call field
  2. FunctionSpec(...)(args...). For standalone function, it's custom_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 of DataSlice)

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.

Metadata

Metadata

Assignees

Labels

python-sdkCocoIndex Python SDK

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions