-
Notifications
You must be signed in to change notification settings - Fork 13
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
feat: add SuperComponent #174
base: main
Are you sure you want to change the base?
Conversation
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
Pull Request Test Coverage Report for Build 12949947646Details
💛 - Coveralls |
@tstadel I've updated the PR and did some clean up. Here is what I would propose: Naming Inheritance Inheriting from Further Examples I updated the example notebook and made the initialization of the Here's another simple super component as an example: from typing import Optional, Dict, Any
from haystack import component, Pipeline
from haystack.components.generators.chat import AzureOpenAIChatGenerator, OpenAIChatGenerator, HuggingFaceAPIChatGenerator
from haystack.utils import Secret
from haystack_experimental.core.super_component import SuperComponentBase
_GENERATOR_PROVIDERS = {
"openai": OpenAIChatGenerator,
"azure": AzureOpenAIChatGenerator,
"huggingface": HuggingFaceAPIChatGenerator,
}
@component
class AutoGenerator(SuperComponentBase):
def __init__(
self,
model: str = "openai:gpt-4o",
api_key=Secret.from_env_var("LLM_API_KEY"),
generation_kwargs: Optional[Dict[str, Any]] = None
) -> None:
if ":" not in model:
raise ValueError("Model string must be in format 'provider:model_name'")
provider, model_name = model.split(":")
if provider not in _GENERATOR_PROVIDERS:
raise ValueError(
f"Provider must be one of {list(_GENERATOR_PROVIDERS.keys())}"
)
generator = _GENERATOR_PROVIDERS[provider](
api_key=api_key,
model=model_name,
generation_kwargs=generation_kwargs,
)
pp = Pipeline()
pp.add_component("generator", generator)
super(AutoGenerator, self).__init__(pipeline=pp) |
# Conflicts: # test/components/tools/__init__.py
BenefitsAn abstraction layer that wraps around pipelines was requested by the community many times (e.g. deepset-ai/haystack#7638). They allow to encapsulate an entire pipeline so that it is easier to organize code and keep an overview over very large pipelines. Additionally, we got feedback that our components are very atomic (which is generally good) and they can be hard to understand by novice users.
At the same time, we are not hiding how these components are implemented. Any advanced Haystack user who understands how to build pipelines can look at the code for our super components and customize it if needed. For deepset Studio, we are giving users the possibility to |
Related Issues
SuperComponents
Supercomponents in general behave like any other component. They have init params, from_dict() and to_dict() methods as usual. The init params typically determine how the internal pipeline is constructed (e.g. which components are used).
Expanding SuperComponents
What makes SuperComponents special is the ability to expand it by calling their
to_super_component_dict()
method. This converts the component to a genericSuperComponent
that contains the pipeline constructed by the SuperComponent. From there on the pipeline can be changed in any way.Load as SuperComponent:
Proposed Changes:
How did you test it?
Notes for the reviewer
Check out the super_components.ipynb to get an idea how it's working
Checklist
fix:
,feat:
,build:
,chore:
,ci:
,docs:
,style:
,refactor:
,perf:
,test:
.