mirror of
https://github.com/neuml/txtai.git
synced 2026-10-12 02:19:52 +00:00
Add ability to resolve workflows within applications, closes #290
This commit is contained in:
@@ -242,9 +242,14 @@ class Application:
|
||||
resolved function
|
||||
"""
|
||||
|
||||
# Check if function is a pipeline
|
||||
if function in self.pipelines:
|
||||
return self.pipelines[function]
|
||||
|
||||
# Check if function is a workflow
|
||||
if function in self.workflows:
|
||||
return self.workflows[function]
|
||||
|
||||
# Attempt to resolve action as a callable function
|
||||
return PipelineFactory.create({}, function)
|
||||
|
||||
|
||||
@@ -477,6 +477,30 @@ class TestWorkflow(unittest.TestCase):
|
||||
"And another sentence to split.",
|
||||
)
|
||||
|
||||
def testYamlWorkflowTask(self):
|
||||
"""
|
||||
Tests YAML workflow with a workflow task
|
||||
"""
|
||||
|
||||
# Create function and add to module
|
||||
def action(elements):
|
||||
return [x * 2 for x in elements]
|
||||
|
||||
sys.modules[__name__].action = action
|
||||
|
||||
workflow = """
|
||||
workflow:
|
||||
run:
|
||||
tasks:
|
||||
- testworkflow.action
|
||||
flow:
|
||||
tasks:
|
||||
- run
|
||||
"""
|
||||
|
||||
app = API(workflow)
|
||||
self.assertEqual(list(app.workflow("flow", [1, 2])), [2, 4])
|
||||
|
||||
def testYamlTransformWorkflow(self):
|
||||
"""
|
||||
Test reading a YAML transform workflow in Python.
|
||||
|
||||
Reference in New Issue
Block a user