deepset-ai / canals

A component orchestration engine
https://deepset-ai.github.io/canals/
Apache License 2.0
27 stars 3 forks source link

feat: read defaults from `run()` signature #166

Closed ZanSara closed 11 months ago

ZanSara commented 11 months ago

Follow up of https://github.com/deepset-ai/canals/pull/148


Currently, input sockets are read from the set_input_types call only, and therefore all count as mandatory. However, one may want to still specify defaults for non-dynamic inputs, such as what PromptBuilder does now:

class PromptBuilder:

    def __init__(self, ...):
        ....
        component.set_input_types(self, **dynamic_input_slots)

    def run(self, messages: Optional[List[ChatMessage]] = None, **kwargs): 
        ...

This PR makes the signature above work by reading the signature of run() even when __canals_inputs__ already exists, and makes sure to add additional sockets and to check whether they have defaults.

It also adds a sample component showing this signature (FString, similar to PromptBuilder), unit tests for it, and a small integration test with a Pipeline using such component.