Skip to content

Python: implement Chat history, and refactor prompt config/prompt config template#5023

Merged
moonbox3 merged 31 commits intomicrosoft:python_kernel_args_latestfrom
moonbox3:chat_history_and_prompt_config
Feb 22, 2024
Merged

Python: implement Chat history, and refactor prompt config/prompt config template#5023
moonbox3 merged 31 commits intomicrosoft:python_kernel_args_latestfrom
moonbox3:chat_history_and_prompt_config

Conversation

@moonbox3
Copy link
Collaborator

@moonbox3 moonbox3 commented Feb 14, 2024

Motivation and Context

This PR addresses a few of our remaining urgent work items: #4856, #4630.

Description

In this PR:

  • The prompt template/prompt template config is refactored to be similar to the dotnet versions.
  • The KernelPromptTemplate is introduced as the default prompt template (will need to make it more dynamic in the future when we have other prompt templates, like handlebars or jinja2).
  • The methods related to create_semantic_function were removed and it their places a method create_function_from_prompt was added.
  • ChatHistory was introduced as a way to take over what ChatMessage was doing. ChatHistory is passed into the complete chat/text methods.
  • As of these latest changes, all unit and integration tests are passing.
  • New kernel examples were added to exercise this new code.

Contribution Checklist

moonbox3 and others added 4 commits February 14, 2024 11:33
…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.
@moonbox3 moonbox3 requested a review from a team as a code owner February 14, 2024 21:18
@shawncal shawncal added the python Pull requests for the Python Semantic Kernel label Feb 14, 2024
@moonbox3 moonbox3 changed the title Python: implement Chat history and ai service selector, and refactor prompt config/prompt config templat Python: implement Chat history and ai service selector, and refactor prompt config/prompt config template Feb 14, 2024
Copy link
Member

@eavanvalkenburg eavanvalkenburg left a comment

Choose a reason for hiding this comment

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

Still some work to do, but the basics are there!

@moonbox3 moonbox3 changed the title Python: implement Chat history and ai service selector, and refactor prompt config/prompt config template Python: implement Chat history, and refactor prompt config/prompt config template Feb 15, 2024
eavanvalkenburg and others added 8 commits February 16, 2024 13:06
### 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 😄
Copy link
Member

@eavanvalkenburg eavanvalkenburg left a comment

Choose a reason for hiding this comment

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

what a lot of work, nice going! some comments added!

moonbox3 and others added 5 commits February 20, 2024 13:02
### 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 😄
@eavanvalkenburg eavanvalkenburg force-pushed the python_kernel_args_latest branch from fe5887e to a9e9085 Compare February 20, 2024 12:03
Copy link
Member

@eavanvalkenburg eavanvalkenburg left a comment

Choose a reason for hiding this comment

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

man, what a load of work, looking good overall, lots of small notes!

eavanvalkenburg and others added 4 commits February 21, 2024 10:15
…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.
@moonbox3 moonbox3 merged commit ec02d89 into microsoft:python_kernel_args_latest Feb 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation memory python Pull requests for the Python Semantic Kernel

Projects

Archived in project

4 participants