Skip to content

Commit 53b029b

Browse files
committed
fix: feedback review
Signed-off-by: va <va@us.ibm.com>
1 parent 80d853f commit 53b029b

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

python/beeai_framework/tools/tool.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515

1616
import inspect
17-
import re
1817
from abc import ABC, abstractmethod
1918
from collections.abc import Callable
2019
from typing import Any, Generic, TypeVar
@@ -27,6 +26,7 @@
2726
from beeai_framework.retryable import Retryable, RetryableConfig, RetryableContext, RetryableInput
2827
from beeai_framework.tools.errors import ToolError, ToolInputValidationError
2928
from beeai_framework.utils import BeeLogger
29+
from beeai_framework.utils.strings import to_safe_word
3030

3131
logger = BeeLogger(__name__)
3232

@@ -197,10 +197,8 @@ class FunctionTool(Tool):
197197

198198
def __init__(self, options: dict[str, Any] | None = None) -> None:
199199
super().__init__(options)
200-
# replace any non-alphanumeric char with _
201-
formatted_name = re.sub(r"\W+", "_", self.name).lower()
202200
self.emitter = Emitter.root().child(
203-
namespace=["tool", "custom", formatted_name],
201+
namespace=["tool", "custom", to_safe_word(self.name)],
204202
creator=self,
205203
)
206204

python/beeai_framework/utils/strings.py

+5
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,8 @@ def create_strenum(name: str, keys: Sequence[str]) -> type[StrEnum]:
4646

4747
def to_json(input: Any, *, indent: int | None = None) -> str:
4848
return json.dumps(input, ensure_ascii=False, default=lambda o: o.__dict__, sort_keys=True, indent=indent)
49+
50+
51+
def to_safe_word(phrase: str) -> str:
52+
# replace any non-alphanumeric char with _
53+
return re.sub(r"\W+", "_", phrase).lower()

python/beeai_framework/workflows/workflow.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
import asyncio
1616
import inspect
17-
import re
1817
from collections.abc import Awaitable, Callable
1918
from dataclasses import field
2019
from typing import Any, ClassVar, Final, Generic, Literal
@@ -27,6 +26,7 @@
2726
from beeai_framework.emitter.emitter import Emitter
2827
from beeai_framework.errors import FrameworkError
2928
from beeai_framework.utils.models import ModelLike, check_model, to_model, to_model_optional
29+
from beeai_framework.utils.strings import to_safe_word
3030
from beeai_framework.utils.types import MaybeAsync
3131
from beeai_framework.workflows.errors import WorkflowError
3232

@@ -84,10 +84,8 @@ def __init__(self, schema: type[T], name: str = "Workflow") -> None:
8484
self._steps: dict[K, WorkflowStepDefinition[T, K]] = {}
8585
self._start_step: K | None = None
8686

87-
# replace any non-alphanumeric char with _
88-
formatted_name = re.sub(r"\W+", "_", self._name).lower()
8987
self.emitter = Emitter.root().child(
90-
namespace=["workflow", formatted_name],
88+
namespace=["workflow", to_safe_word(self._name)],
9189
creator=self,
9290
)
9391

0 commit comments

Comments
 (0)