haystack icon indicating copy to clipboard operation
haystack copied to clipboard

Custom function support for Shaper

Open sahilshaheen opened this issue 1 year ago • 1 comments

Is your feature request related to a problem? Please describe. Currently, the Shaper class initialiser restricts us from passing our own functions.

def __init__(
        self,
        func: str,
        outputs: List[str],
        inputs: Optional[Dict[str, Union[List[str], str]]] = None,
        params: Optional[Dict[str, Any]] = None,
        publish_outputs: Union[bool, List[str]] = True,
    ):
    super().__init__()
    self.function = REGISTERED_FUNCTIONS[func]

Describe the solution you'd like Modify the initialiser to accept str or Callable objects and handle them accordingly

def __init__(
        self,
        func: Union[str, Callable[..., Any]],
        outputs: List[str],
        inputs: Optional[Dict[str, Union[List[str], str]]] = None,
        params: Optional[Dict[str, Any]] = None,
        publish_outputs: Union[bool, List[str]] = True,
    ):
    super().__init__()
    if inspect.isfunction(func):
        self.function = func
    else:
        self.function = REGISTERED_FUNCTIONS[func]

Describe alternatives you've considered I'm currently using the class by initialising with one of the allowed func values and overriding self.function

sahilshaheen avatar Apr 05 '23 17:04 sahilshaheen

Hey @sahilshaheen, Shaper is a node meant to be compatible with serialization to YAML, so arbitrary callables are hard to fit in this model. While we might actually take this feature request soon enough, for now I'd recommend you to write a small custom node that performs the conversion you want. https://docs.haystack.deepset.ai/docs/custom_nodes.

I'll leave this issue open so that we can pick it up later.

ZanSara avatar Apr 11 '23 16:04 ZanSara

https://github.com/deepset-ai/haystack/issues/6035 seems related. With the chat format mentioned there we would support function calling with LLMs.

Timoeller avatar Oct 13 '23 14:10 Timoeller