Python: implement Chat history, and refactor prompt config/prompt config template#5023
Merged
moonbox3 merged 31 commits intomicrosoft:python_kernel_args_latestfrom Feb 22, 2024
Conversation
…mptConfig/PromptTemplateConfig to be similar to dotnet. Update both unit and integration tests. Implement a beginning of an ai service selector as ChatPromptTemplate is going away.
This was
linked to
issues
Feb 14, 2024
Python: add ChatHistory concept in sync with dotnet and adapt chat_prompt_template accordingly
#4856
Closed
eavanvalkenburg
requested changes
Feb 15, 2024
Member
eavanvalkenburg
left a comment
There was a problem hiding this comment.
Still some work to do, but the basics are there!
python/semantic_kernel/template_engine/protocols/prompt_templating_engine.py
Show resolved
Hide resolved
### 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 😄
…o chat_history_and_prompt_config
### 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. --> ### Description <!-- 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: --> - [ ] The code builds clean without any errors or warnings - [ ] 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 - [ ] All unit tests pass, and I have added new tests where possible - [ ] I didn't break anyone 😄
eavanvalkenburg
requested changes
Feb 19, 2024
Member
eavanvalkenburg
left a comment
There was a problem hiding this comment.
what a lot of work, nice going! some comments added!
### 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 😄
### 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. --> ### Description <!-- 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: --> - [ ] The code builds clean without any errors or warnings - [ ] 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 - [ ] All unit tests pass, and I have added new tests where possible - [ ] I didn't break anyone 😄
fe5887e to
a9e9085
Compare
…te methods. Update more Jupyter notebooks. All tests passing.
…hanges. Still a few more todo.
eavanvalkenburg
requested changes
Feb 21, 2024
Member
eavanvalkenburg
left a comment
There was a problem hiding this comment.
man, what a load of work, looking good overall, lots of small notes!
python/semantic_kernel/connectors/ai/chat_completion_client_base.py
Outdated
Show resolved
Hide resolved
python/semantic_kernel/connectors/ai/chat_completion_client_base.py
Outdated
Show resolved
Hide resolved
python/semantic_kernel/connectors/ai/open_ai/contents/open_ai_chat_message_content.py
Show resolved
Hide resolved
python/semantic_kernel/prompt_template/kernel_prompt_template.py
Outdated
Show resolved
Hide resolved
python/tests/unit/models/ai/chat_completion/test_chat_history.py
Outdated
Show resolved
Hide resolved
python/tests/unit/models/ai/chat_completion/test_chat_history.py
Outdated
Show resolved
Hide resolved
…th named_args added (microsoft#5014) ### 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. --> This implements ADR0009 multiple arguments in a template function. Closes microsoft#5003 ### Description <!-- Describe your changes, the overall approach, the underlying design. These notes will help understanding how your code works. Thanks! --> Added NamedArgBlocks class and updated codetokenizer and templatetokenizer to recognize these and implement them, add code to CodeBlock class to use it. ### 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 😄
…prompt. Add chat history tests, and chathistory serialization test. Other small updates. All tests passing.
2a3e52a to
a2aaf8c
Compare
eavanvalkenburg
approved these changes
Feb 22, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation and Context
This PR addresses a few of our remaining urgent work items: #4856, #4630.
Description
In this PR:
create_semantic_functionwere removed and it their places a methodcreate_function_from_promptwas added.Contribution Checklist