Skip to content

armgit / laya

Public Imported from GitHub
0

Non-autoregressive System 1 decision engine. Typed choice, score and yes/no decisions over any text in a single forward pass, in 100+ languages, with a router that picks the right checkpoint per request.

fix(integrations): one LayaLowConfidenceError for LlamaIndex and CrewAI, local URLs in tests

Nandakishored5f7de4ad67
diff --git a/laya/integrations/__init__.py b/laya/integrations/__init__.py
index 7eb80c55..f99ed903 100644
--- a/laya/integrations/__init__.py
+++ b/laya/integrations/__init__.py
@@ -1,8 +1,8 @@
"""Third-party agent and framework integrations for Laya."""
+from ._errors import LayaLowConfidenceError
from .crewai import (
CrewRouteDecision,
LayaCrewRouter,
- LayaLowConfidenceError,
LayaTaskGuard,
LayaTaskGuardError,
)
@@ -15,7 +15,6 @@ from .langchain import (
LayaTriage,
)
from .llamaindex import (
- LayaLowConfidenceError,
LayaMultiSelector,
LayaQueryRouter,
LayaSingleSelector,
diff --git a/laya/integrations/_errors.py b/laya/integrations/_errors.py
new file mode 100644
index 00000000..a126abfb
--- /dev/null
+++ b/laya/integrations/_errors.py
@@ -0,0 +1,12 @@
+"""Exceptions shared by the framework integrations."""
+from typing import Any, Dict
+
+
+class LayaLowConfidenceError(ValueError):
+ """Raised when a routing decision falls below the confidence threshold and no fallback is set."""
+
+ def __init__(self, message: str, confidence: float, threshold: float, raw_decision: Dict[str, Any]):
+ super().__init__(message)
+ self.confidence = confidence
+ self.threshold = threshold
+ self.raw_decision = raw_decision
diff --git a/laya/integrations/crewai.py b/laya/integrations/crewai.py
index 4ed9da0f..5c154c71 100644
--- a/laya/integrations/crewai.py
+++ b/laya/integrations/crewai.py
@@ -51,14 +51,8 @@ class LayaTaskGuardError(ValueError):
self.raw_decision = raw_decision
-class LayaLowConfidenceError(ValueError):
- """Raised when task routing confidence falls below the configured threshold and no fallback is set."""
-
- def __init__(self, message: str, confidence: float, threshold: float, raw_decision: Dict[str, Any]):
- super().__init__(message)
- self.confidence = confidence
- self.threshold = threshold
- self.raw_decision = raw_decision
+# One class for every integration, so `except LayaLowConfidenceError` catches all of them.
+from ._errors import LayaLowConfidenceError # noqa: E402
@dataclass
diff --git a/laya/integrations/llamaindex.py b/laya/integrations/llamaindex.py
index 4bf8f960..6e7615a2 100644
--- a/laya/integrations/llamaindex.py
+++ b/laya/integrations/llamaindex.py
@@ -60,14 +60,8 @@ except ImportError:
return self.query_str
-class LayaLowConfidenceError(ValueError):
- """Raised when a routing decision falls below the confidence threshold and no fallback is set."""
-
- def __init__(self, message: str, confidence: float, threshold: float, raw_decision: Dict[str, Any]):
- super().__init__(message)
- self.confidence = confidence
- self.threshold = threshold
- self.raw_decision = raw_decision
+# One class for every integration, so `except LayaLowConfidenceError` catches all of them.
+from ._errors import LayaLowConfidenceError # noqa: E402
def _extract_query_str(query: Union[str, QueryBundle, Any]) -> str:
diff --git a/tests/test_crewai.py b/tests/test_crewai.py
index b0a02f93..c2587763 100644
--- a/tests/test_crewai.py
+++ b/tests/test_crewai.py
@@ -270,7 +270,7 @@ with patch("urllib.request.build_opener") as mock_build_opener:
mock_build_opener.return_value = mock_opener
remote_router = LayaCrewRouter(
- base_url="https://api.laya.ai",
+ base_url="http://localhost:8000",
api_key="sk-crew-key",
)
dec_remote = remote_router.route("Analyze codebase", agents)
@@ -279,7 +279,7 @@ with patch("urllib.request.build_opener") as mock_build_opener:
# Verify request headers and URL
call_args = mock_opener.open.call_args
req = call_args[0][0]
- check("remote/url", req.full_url, "https://api.laya.ai/v1/systemone")
+ check("remote/url", req.full_url, "http://localhost:8000/v1/systemone")
check("remote/auth", req.headers.get("Authorization"), "Bearer sk-crew-key")
diff --git a/tests/test_llamaindex.py b/tests/test_llamaindex.py
index e056599a..7b3cbc23 100644
--- a/tests/test_llamaindex.py
+++ b/tests/test_llamaindex.py
@@ -380,7 +380,7 @@ with patch("urllib.request.build_opener") as mock_build_opener:
mock_build_opener.return_value = mock_opener
remote_selector = LayaSingleSelector(
- base_url="https://api.laya.ai",
+ base_url="http://localhost:8000",
api_key="sk-test-token",
)
res_remote = remote_selector.select(tools, "Query via remote server")
@@ -389,7 +389,7 @@ with patch("urllib.request.build_opener") as mock_build_opener:
# Check request headers and URL
call_args = mock_opener.open.call_args
req = call_args[0][0]
- check("remote/url", req.full_url, "https://api.laya.ai/v1/systemone")
+ check("remote/url", req.full_url, "http://localhost:8000/v1/systemone")
check("remote/auth", req.headers.get("Authorization"), "Bearer sk-test-token")