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: Kernel service revamp and AIServiceSelector #5050

Conversation

eavanvalkenburg
Copy link
Member

Motivation and Context

Implements the AI Service Selector mechanism
Revamps and simplifies the services in the Kernel
Made service_id required field on all services

Description

  • Removed the individual service fields in kernel, replaced with single one, with dict[str, Class] as type
  • Also removed default_service fields from kernel
  • Reordered methods in Kernel and added region notes for easier folding in IDE
  • Added new service management methods incl tests, removed old ones.
  • Removed service linking to default service from kernel_function
  • Added AIServiceSelector class, single method that can be overridden, returns service and execution_settings with the right type
  • Removed usage of chat_prompt related fields, now checks if service is ChatCompletion and then usage that, otherwise falls back to TextCompletion
  • Added kernel test folder, with kernel_service_management tests, completely covering service related functions

Contribution Checklist

@eavanvalkenburg eavanvalkenburg requested a review from a team as a code owner February 16, 2024 12:41
@shawncal shawncal added the python Pull requests for the Python Semantic Kernel label Feb 16, 2024
@@ -92,8 +91,8 @@ class KernelFunction(KernelBaseModel):
return_parameter: Optional[KernelParameterMetadata] = None
function: Callable[..., Any] = Field(...)
plugins: Optional["KernelPluginCollection"] = Field(default=None)
ai_service: Optional[Union[TextCompletionClientBase, ChatCompletionClientBase]] = Field(default=None)
prompt_execution_settings: PromptExecutionSettings = Field(default_factory=PromptExecutionSettings)
# ai_service: Optional[Union[TextCompletionClientBase, ChatCompletionClientBase]] = Field(default=None)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed

if param.name == "client":
function_arguments[param.name] = self.ai_service
if param.name == "service":
function_arguments[param.name] = kernel.select_ai_service(self, arguments)[0]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we do this kernel.select_ai_service call one time and already have the service and request_settings available for assignment?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved it here because some functions don't use it, guess there is a different way to do it but this worked and the function isn't heavy, but I guess someone can override with something more complex... I'll have a look.

@moonbox3 moonbox3 merged commit 956f5c1 into microsoft:python_kernel_args_latest Feb 16, 2024
3 checks passed
eavanvalkenburg added a commit that referenced this pull request Feb 20, 2024
### Motivation and Context

<!-- 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.
-->
Implements the AI Service Selector mechanism
Revamps and simplifies the services in the Kernel
Made service_id required field on all services

### Description

<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->
- Removed the individual service fields in kernel, replaced with single
one, with dict[str, Class] as type
- Also removed default_service fields from kernel
- Reordered methods in Kernel and added region notes for easier folding
in IDE
- Added new service management methods incl tests, removed old ones.
- Removed service linking to default service from kernel_function
- Added AIServiceSelector class, single method that can be overridden,
returns service and execution_settings with the right type
- Removed usage of chat_prompt related fields, now checks if service is
ChatCompletion and then usage that, otherwise falls back to
TextCompletion
- Added kernel test folder, with kernel_service_management tests,
completely covering service related functions



### 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
- [ ] I didn't break anyone 😄
eavanvalkenburg added a commit that referenced this pull request Feb 22, 2024
### Motivation and Context

<!-- 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.
-->
Implements the AI Service Selector mechanism
Revamps and simplifies the services in the Kernel
Made service_id required field on all services

### Description

<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->
- Removed the individual service fields in kernel, replaced with single
one, with dict[str, Class] as type
- Also removed default_service fields from kernel
- Reordered methods in Kernel and added region notes for easier folding
in IDE
- Added new service management methods incl tests, removed old ones.
- Removed service linking to default service from kernel_function
- Added AIServiceSelector class, single method that can be overridden,
returns service and execution_settings with the right type
- Removed usage of chat_prompt related fields, now checks if service is
ChatCompletion and then usage that, otherwise falls back to
TextCompletion
- Added kernel test folder, with kernel_service_management tests,
completely covering service related functions



### 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
- [ ] I didn't break anyone 😄
@eavanvalkenburg eavanvalkenburg deleted the kernel_services_revamp branch February 27, 2024 10:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
python Pull requests for the Python Semantic Kernel
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants