Skip to content
This repository has been archived by the owner on Jul 20, 2024. It is now read-only.

Commit

Permalink
feat: Add remove_special_characters tool
Browse files Browse the repository at this point in the history
  • Loading branch information
ayoubmrx committed Feb 13, 2024
1 parent c03f0d5 commit 7dd253f
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM hyko-sdk:latest


WORKDIR /app

COPY . .
RUN poetry run pip install regex

CMD ["poetry", "run", "uvicorn", "--host", "0.0.0.0", "--port", "3000","main:func"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import re

from metadata import Inputs, Outputs, Params, func


@func.on_execute
async def main(inputs: Inputs, params: Params) -> Outputs:
"""
Remove special characters and punctuation from the text, keeping only alphanumeric characters and spaces.
Args:
- text (str): The input text from which special characters and punctuation will be removed.
Returns:
- str: The text with special characters and punctuation removed.
"""
# Define the regular expression pattern to match non-alphanumeric characters (excluding spaces)
pattern = r"[^a-zA-Z0-9\s]"

# Replace non-alphanumeric characters with an empty string
cleaned_text = re.sub(pattern, "", inputs.text)

return Outputs(result=" ".join(cleaned_text.strip().split()))
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from pydantic import Field

from hyko_sdk.function import SDKFunction
from hyko_sdk.metadata import CoreModel

func = SDKFunction(
description="A function to remove special characters and punctuation from text."
)


@func.set_input
class Inputs(CoreModel):
text: str = Field(
...,
description="The input text from which special characters and punctuation will be removed.",
)


@func.set_param
class Params(CoreModel):
pass


@func.set_output
class Outputs(CoreModel):
result: str = Field(
..., description="The text with special characters and punctuation removed."
)

0 comments on commit 7dd253f

Please sign in to comment.