deepset-ai / haystack

AI orchestration framework to build customizable, production-ready LLM applications. Connect components (models, vector DBs, file converters) to pipelines or agents that can interact with your data. With advanced retrieval methods, it's best suited for building RAG, question answering, semantic search or conversational agent chatbots.
https://haystack.deepset.ai
Apache License 2.0
17.72k stars 1.92k forks source link

`component.set_output_types()` overrides `@component.output_types()` if both are used in the same Component #8372

Closed silvanocerza closed 1 month ago

silvanocerza commented 2 months ago

Describe the bug

Currently it's possible to both decorate a Component's run method using @component.output_types() and call component.set_output_types() when initialising it.

component.set_output_types() overrides whatever has been set by @component.output_types().

This behaviour is confusing and should be prevented.

Expected behavior

An exception is raised.

Additional context

This is related to #8280

To Reproduce

This should raise an exception.

from typing import List

from haystack import component

class MockComponent:
    def __init__(self):
        component.set_output_types(self, value=List[int])

    @component.output_types(value=int)
    def run(self):
        return {"value": 1}