Skip to content

armgit / txtai

Public Imported from GitHub
0

💡 All-in-one AI framework for semantic search, LLM orchestration and language model workflows

Raise error when API task action not found. Fix scoring key reference.

davidmezzetti709937dfee0d
diff --git a/src/python/txtai/api/base.py b/src/python/txtai/api/base.py
index 04340829..5b2a9e7b 100644
--- a/src/python/txtai/api/base.py
+++ b/src/python/txtai/api/base.py
@@ -164,20 +164,20 @@ class API:
def function(self, function):
"""
- Get a handle to a callable function
+ Get a handle to a callable function.
+
+ Args:
+ function: function name
+
+ Returns:
+ resolved function
"""
if function in self.pipelines:
return self.pipelines[function]
- # pylint: disable=W0702
- try:
- # Attempt to resolve action as a callable function
- return PipelineFactory.create({}, function)
- except:
- pass
-
- return None
+ # Attempt to resolve action as a callable function
+ return PipelineFactory.create({}, function)
def limit(self, limit):
"""
@@ -301,7 +301,7 @@ class API:
elif self.embeddings and self.config.get("writable") and self.documents:
with self.lock:
# Build scoring index if scoring method provided
- if self.config.get("scoring"):
+ if self.embeddings.scoring:
self.embeddings.score(self.documents)
# Build embeddings index
diff --git a/test/python/testapi/testworkflow.py b/test/python/testapi/testworkflow.py
index 3cef7a44..b2dfdf8d 100644
--- a/test/python/testapi/testworkflow.py
+++ b/test/python/testapi/testworkflow.py
@@ -37,7 +37,6 @@ workflow:
labels:
tasks:
- action: labels
- initialize: testnotfound
args: [[positive, negative]]
multiaction:
tasks:
diff --git a/test/python/testworkflow.py b/test/python/testworkflow.py
index 661c80af..5fa1eaa9 100644
--- a/test/python/testworkflow.py
+++ b/test/python/testworkflow.py
@@ -297,8 +297,8 @@ class TestWorkflow(unittest.TestCase):
config = """
# Embeddings index
writable: true
- scoring: bm25
embeddings:
+ scoring: bm25
path: google/bert_uncased_L-2_H-128_A-2
# Text segmentation
@@ -336,3 +336,20 @@ class TestWorkflow(unittest.TestCase):
list(app.workflow("segment", ["This is a test sentence. And another sentence to split."])),
["This is a test sentence.", "And another sentence to split."],
)
+
+ def testYamlError(self):
+ """
+ Tests reading a YAML workflow with errors.
+ """
+
+ # Read from string
+ config = """
+ # Workflow definitions
+ workflow:
+ error:
+ tasks:
+ - action: error
+ """
+
+ with self.assertRaises(KeyError):
+ API(config)