Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python: str representation of SKFunctions are very verbose #4280

Closed
moonbox3 opened this issue Dec 14, 2023 · 0 comments · Fixed by #4283
Closed

Python: str representation of SKFunctions are very verbose #4280

moonbox3 opened this issue Dec 14, 2023 · 0 comments · Fixed by #4283
Assignees
Labels
bug Something isn't working python Pull requests for the Python Semantic Kernel

Comments

@moonbox3
Copy link
Contributor

Describe the bug
After upgrading to Pydantic 2, the str representation of SKFunctions are very verbose while running Notebooks:

{'lowercase': SKFunction(FUNCTION_PARAM_NAME_REGEX='^[0-9A-Za-z_]$', FUNCTION_NAME_REGEX='^[0-9A-Za-z_]$', SKILL_NAME_REGEX='^[0-9A-Za-z_]$'),
'trim': SKFunction(FUNCTION_PARAM_NAME_REGEX='^[0-9A-Za-z_]
$', FUNCTION_NAME_REGEX='^[0-9A-Za-z_]$', SKILL_NAME_REGEX='^[0-9A-Za-z_]$'),
'trim_end': SKFunction(FUNCTION_PARAM_NAME_REGEX='^[0-9A-Za-z_]$', FUNCTION_NAME_REGEX='^[0-9A-Za-z_]$', SKILL_NAME_REGEX='^[0-9A-Za-z_]$'),
'trim_start': SKFunction(FUNCTION_PARAM_NAME_REGEX='^[0-9A-Za-z_]
$', FUNCTION_NAME_REGEX='^[0-9A-Za-z_]$', SKILL_NAME_REGEX='^[0-9A-Za-z_]$'),
'uppercase': SKFunction(FUNCTION_PARAM_NAME_REGEX='^[0-9A-Za-z_]$', FUNCTION_NAME_REGEX='^[0-9A-Za-z_]$', SKILL_NAME_REGEX='^[0-9A-Za-z_]*$')}

To Reproduce

  1. Get latest code or ref the latest SK Python package (0.4.2.dev0).
  2. Run the 05-using-the-planner notebook.
  3. In the cell where we create an SKFunction like:

from semantic_kernel.core_skills import FileIOSkill, MathSkill, TextSkill, TimeSkill
kernel.import_skill(MathSkill(), "math")
kernel.import_skill(FileIOSkill(), "fileIO")
kernel.import_skill(TimeSkill(), "time")
kernel.import_skill(TextSkill(), "text")

  1. You will see after running the notebook cell:

{'lowercase': SKFunction(FUNCTION_PARAM_NAME_REGEX='^[0-9A-Za-z_]$', FUNCTION_NAME_REGEX='^[0-9A-Za-z_]$', SKILL_NAME_REGEX='^[0-9A-Za-z_]$'),
'trim': SKFunction(FUNCTION_PARAM_NAME_REGEX='^[0-9A-Za-z_]
$', FUNCTION_NAME_REGEX='^[0-9A-Za-z_]$', SKILL_NAME_REGEX='^[0-9A-Za-z_]$'),
'trim_end': SKFunction(FUNCTION_PARAM_NAME_REGEX='^[0-9A-Za-z_]$', FUNCTION_NAME_REGEX='^[0-9A-Za-z_]$', SKILL_NAME_REGEX='^[0-9A-Za-z_]$'),
'trim_start': SKFunction(FUNCTION_PARAM_NAME_REGEX='^[0-9A-Za-z_]
$', FUNCTION_NAME_REGEX='^[0-9A-Za-z_]$', SKILL_NAME_REGEX='^[0-9A-Za-z_]$'),
'uppercase': SKFunction(FUNCTION_PARAM_NAME_REGEX='^[0-9A-Za-z_]$', FUNCTION_NAME_REGEX='^[0-9A-Za-z_]$', SKILL_NAME_REGEX='^[0-9A-Za-z_]*$')}

Expected behavior
We don't need to expose the SKFunctionBase attributes. Something like this should be fine:

'lowercase': SKFunction()

@moonbox3 moonbox3 self-assigned this Dec 14, 2023
@shawncal shawncal added python Pull requests for the Python Semantic Kernel triage labels Dec 14, 2023
@moonbox3 moonbox3 added bug Something isn't working and removed triage labels Dec 14, 2023
github-merge-queue bot pushed a commit that referenced this issue Dec 16, 2023
### Motivation and Context

Fixes #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>
Bryan-Roe pushed a commit to Bryan-Roe-ai/semantic-kernel that referenced this issue Oct 6, 2024
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working python Pull requests for the Python Semantic Kernel
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants