mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-15 13:05:59 +08:00
feat(api): Introduce a VariableLoader interface.
The `VariableLoader` interface is used to load referenced variables when running a single node.
This commit is contained in:
parent
0984f580a3
commit
141f9b4d51
38
api/core/workflow/variable_loader.py
Normal file
38
api/core/workflow/variable_loader.py
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
import abc
|
||||||
|
from typing import Protocol
|
||||||
|
|
||||||
|
from core.variables import Variable
|
||||||
|
|
||||||
|
|
||||||
|
class VariableLoader(Protocol):
|
||||||
|
"""Interface for loading variables based on selectors.
|
||||||
|
|
||||||
|
A `VariableLoader` is responsible for retrieving additional variables required during the execution
|
||||||
|
of a single node, which are not provided as user inputs.
|
||||||
|
|
||||||
|
NOTE(QuantumGhost): Typically, all variables loaded by a `VariableLoader` should belong to the same
|
||||||
|
application and share the same `app_id`. However, this interface does not enforce that constraint,
|
||||||
|
and the `app_id` parameter is intentionally omitted from `load_variables` to achieve separation of
|
||||||
|
concern and allow for flexible implementations.
|
||||||
|
|
||||||
|
Implementations of `VariableLoader` should almost always have an `app_id` parameter in
|
||||||
|
their constructor.
|
||||||
|
|
||||||
|
TODO(QuantumGhost): this is a temporally workaround. If we can move the creation of node instance into
|
||||||
|
`WorkflowService.single_step_run`, we may get rid of this interface.
|
||||||
|
"""
|
||||||
|
|
||||||
|
@abc.abstractmethod
|
||||||
|
def load_variables(self, selectors: list[list[str]]) -> list[Variable]:
|
||||||
|
"""Load variables based on the provided selectors. If the selectors are empty,
|
||||||
|
this method should return an empty list.
|
||||||
|
|
||||||
|
The order of the returned variables is not guaranteed. If the caller wants to ensure
|
||||||
|
a specific order, they should sort the returned list themselves.
|
||||||
|
|
||||||
|
:param: selectors: a list of string list, each inner list should have at least two elements:
|
||||||
|
- the first element is the node ID,
|
||||||
|
- the second element is the variable name.
|
||||||
|
:return: a list of Variable objects that match the provided selectors.
|
||||||
|
"""
|
||||||
|
pass
|
Loading…
x
Reference in New Issue
Block a user