Skip to content

Commit

Permalink
Python: remove unnecessary class attributes from SKFunctionBase. (mic…
Browse files Browse the repository at this point in the history
…rosoft#4283)

### Motivation and Context

Fixes microsoft#4280. Currently, the str representation of SK functions look
verbose:

'uppercase': SKFunction(FUNCTION_PARAM_NAME_REGEX='^[0-9A-Za-z_]*$',
FUNCTION_NAME_REGEX='^[0-9A-Za-z_]*$',
SKILL_NAME_REGEX='^[0-9A-Za-z_]*$')

<!-- Thank you for your contribution to the semantic-kernel repo!
Please help reviewers and future users, providing the following
information:
  1. Why is this change required?
  2. What problem does it solve?
  3. What scenario does it contribute to?
  4. If it fixes an open issue, please link to the issue here.
-->

### Description

This PR removes unnecessary class attributes from SKFunctionBase and
exposes some constants in utils/validation.

<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->

### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [X] The code builds clean without any errors or warnings
- [X] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [X] All unit tests pass, and I have added new tests where possible
- [X] I didn't break anyone 😄

---------

Co-authored-by: Evan Mattson <evan.mattson@microsoft.com>
  • Loading branch information
2 people authored and BR committed Oct 6, 2024
1 parent 51d9f75 commit 3d8f0d6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
4 changes: 0 additions & 4 deletions python/semantic_kernel/orchestration/sk_function_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@


class SKFunctionBase(SKBaseModel):
FUNCTION_PARAM_NAME_REGEX: str = r"^[0-9A-Za-z_]*$"
FUNCTION_NAME_REGEX: str = r"^[0-9A-Za-z_]*$"
SKILL_NAME_REGEX: str = r"^[0-9A-Za-z_]*$"

@property
@abstractmethod
def name(self) -> str:
Expand Down
8 changes: 5 additions & 3 deletions python/semantic_kernel/utils/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
from re import match as re_match
from typing import Optional

# Validation regexes
SKILL_NAME_REGEX = r"^[0-9A-Za-z_]*$"
FUNCTION_NAME_REGEX = r"^[0-9A-Za-z_]*$"
FUNCTION_PARAM_NAME_REGEX = r"^[0-9A-Za-z_]*$"


def validate_skill_name(value: Optional[str]) -> None:
"""
Expand All @@ -18,7 +23,6 @@ def validate_skill_name(value: Optional[str]) -> None:
if not value:
raise ValueError("The skill name cannot be `None` or empty")

SKILL_NAME_REGEX = r"^[0-9A-Za-z_]*$"
if not re_match(SKILL_NAME_REGEX, value):
raise ValueError(
f"Invalid skill name: {value}. Skill "
Expand All @@ -41,7 +45,6 @@ def validate_function_name(value: Optional[str]) -> None:
if not value:
raise ValueError("The function name cannot be `None` or empty")

FUNCTION_NAME_REGEX = r"^[0-9A-Za-z_]*$"
if not re_match(FUNCTION_NAME_REGEX, value):
raise ValueError(
f"Invalid function name: {value}. Function "
Expand All @@ -64,7 +67,6 @@ def validate_function_param_name(value: Optional[str]) -> None:
if not value:
raise ValueError("The function parameter name cannot be `None` or empty")

FUNCTION_PARAM_NAME_REGEX = r"^[0-9A-Za-z_]*$"
if not re_match(FUNCTION_PARAM_NAME_REGEX, value):
raise ValueError(
f"Invalid function parameter name: {value}. Function parameter "
Expand Down

0 comments on commit 3d8f0d6

Please sign in to comment.