Skip to content
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

@component decorator does not detect extra parameters from other decorators #8497

Open
1 task done
tsoernes opened this issue Oct 28, 2024 · 0 comments
Open
1 task done

Comments

@tsoernes
Copy link

tsoernes commented Oct 28, 2024

Describe the bug
When a components run method has a decorator, extra parameters are not detected by the @component decorator.

E.g:

from haystack import Document, component, Pipeline

from typing import Callable
from functools import wraps

def cache(
    directory: Path,
):
    def decorator(func: Callable):
        @wraps(func)
        def wrapper(
            self,
            documents: list[Document],
            *args,
            force_recompute: bool = False,
            **kwargs,
        ) -> dict:
            return {"documents": documents}
        return wrapper
    return decorator
    
@component
class SomeComponent:
    @component.output_types(documents=list[Document])
    @cache(directory=Path())
    def run(
        self,
        documents: list[Document],
    ) -> dict:
        return document

p = Pipeline()
p.add_component("c", SomeComponent())
p.run({"c": {"documents": [], "force_recompute": True}})

Error message
ValueError: Input <decorator_param> not found in component .
ValueError: Input force_recompute not found in component c.
Expected behavior
I want to be able to add extra parameters to "run" using decorators

Additional context
Add any other context about the problem here, like document types / preprocessing steps / settings of reader etc.

To Reproduce
Steps to reproduce the behavior

FAQ Check

System:

  • Haystack version (commit or version number): haystack-ai = "2.6.1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant