Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion cascadeflow/integrations/hermes/classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from __future__ import annotations

import re
from dataclasses import dataclass
from typing import Optional

Expand Down Expand Up @@ -122,10 +123,17 @@ def classify(self, request: HermesDelegationRequest) -> HermesTaskClassification
reason=domain_reason,
)

@staticmethod
def _keyword_in_text(keyword: str, lowered: str) -> bool:
# Match on word boundaries so short keywords (e.g. "ci", "api", "law")
# don't match inside unrelated words like "financial" ("ci") or "always"
# ("law"). Handles multi-word keywords ("stack trace") correctly too.
return re.search(rf"\b{re.escape(keyword)}\b", lowered) is not None

def _detect_domain(self, lowered: str, toolsets: tuple[str, ...]) -> tuple[str, float, str]:
scores: dict[str, int] = {}
for domain, keywords in DOMAIN_KEYWORDS.items():
hits = sum(1 for keyword in keywords if keyword in lowered)
hits = sum(1 for keyword in keywords if self._keyword_in_text(keyword, lowered))
if hits:
scores[domain] = hits

Expand Down
2 changes: 2 additions & 0 deletions tests/test_provider_tool_retry.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import asyncio

from cascadeflow.providers.base import BaseProvider, ModelResponse, RetryConfig
Expand Down
Loading