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: add ChatHistory concept in sync with dotnet and adapt chat_prompt_template accordingly #4856

Closed
eavanvalkenburg opened this issue Feb 2, 2024 · 1 comment · Fixed by #5023 or #5077
Assignees
Labels
kernel Issues or pull requests impacting the core kernel python Pull requests for the Python Semantic Kernel

Comments

@eavanvalkenburg
Copy link
Member

No description provided.

@shawncal shawncal added .NET Issue or Pull requests regarding .NET code python Pull requests for the Python Semantic Kernel triage labels Feb 2, 2024
@github-actions github-actions bot changed the title Python: add ChatHistory concept in sync with dotnet and adapt chat_prompt_template accordingly .Net: Python: add ChatHistory concept in sync with dotnet and adapt chat_prompt_template accordingly Feb 2, 2024
@eavanvalkenburg eavanvalkenburg removed the .NET Issue or Pull requests regarding .NET code label Feb 2, 2024
@github-actions github-actions bot changed the title .Net: Python: add ChatHistory concept in sync with dotnet and adapt chat_prompt_template accordingly Python: add ChatHistory concept in sync with dotnet and adapt chat_prompt_template accordingly Feb 2, 2024
@moonbox3 moonbox3 added kernel Issues or pull requests impacting the core kernel and removed triage labels Feb 2, 2024
@moonbox3
Copy link
Contributor

moonbox3 commented Feb 2, 2024

ChatHistory should be its own class and not part of the chat_prompt_template.

@moonbox3 moonbox3 self-assigned this Feb 2, 2024
moonbox3 added a commit that referenced this issue Feb 22, 2024
…fig template (#5023)

### Motivation and Context

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

<!-- 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

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.

<!-- 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
- [ ] I didn't break anyone 😄

---------

Co-authored-by: Eduard van Valkenburg <eavanvalkenburg@users.noreply.github.com>
github-merge-queue bot pushed a commit that referenced this issue Feb 24, 2024
…new Prompt Templating (#5077)

### 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. -->
Major work to replace the context with Kernel Arguments on the front-end
and Function Results on the back.

Updated the function decorator to a new approach, in line with dotnet.

Revamps the way function are called, allowing native functions to be
completely ignorant of SK, other then the decorator.

This also moves things into the new folder structure in sync with
dotnet.

### Description

<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->
Adds:
- KernelArguments, a dict-like class that replaces the variables in
KernelContext. Closes #4565
- FunctionResult, a class to hold the results of function executions,
includes the function, the value and metadata, as well as two convenient
function to get the value out of it (str and get_inner_content) the
first is generic, the second specifically for KernelContent responses
(from AI services).
- AI Service Selector class, has a default, which is based on the order
in the arguments followed by the order in the functions, can be
overridden to implement your own strategy. Closes #4631
- Introduces ChatHistory and refactors the PromptTemplateConfig. Closes
#4856, #4630
- Improves parsing of templates, will now all validate during creation
and throw an error then, instead of some that do not check for validaty
until used.
- Introduces named_args block and thereby the ability to have multiple
arguments for a function call in a template. Closes #5003

Updates:
- kernel_function decorators, the parameter decorator was removed and
instead we now use Annotated to add a description of a field and we get
the type and required from the function definition.
- core plugins, use the new approach to kernel_function decorators.
- planners, template engines have all been updated to use the kernel and
kernelarguments instead of Context.
- Events have been updated, now use kernelarguments and function_result
- Tokenizers support for named_args and improvements on parsing and
checking.
- Kernel examples and notebooks to use the latest code.
- All unit and integration tests. There is more code coverage now than
before.

Removed:
- kernelContext
- kernel_function_parameter_decorator
- delegate handling code for native functions
- file_io_plugin and tests
- SemanticFunctionConfig
- ChatPromptTemplate

### 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 😄

---------

Co-authored-by: Evan Mattson <evmattso@microsoft.com>
Co-authored-by: Evan Mattson <35585003+moonbox3@users.noreply.github.com>
Co-authored-by: Evan Mattson <evan.mattson@microsoft.com>
LudoCorporateShark pushed a commit to LudoCorporateShark/semantic-kernel that referenced this issue Aug 25, 2024
…new Prompt Templating (microsoft#5077)

### 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. -->
Major work to replace the context with Kernel Arguments on the front-end
and Function Results on the back.

Updated the function decorator to a new approach, in line with dotnet.

Revamps the way function are called, allowing native functions to be
completely ignorant of SK, other then the decorator.

This also moves things into the new folder structure in sync with
dotnet.

### Description

<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->
Adds:
- KernelArguments, a dict-like class that replaces the variables in
KernelContext. Closes microsoft#4565
- FunctionResult, a class to hold the results of function executions,
includes the function, the value and metadata, as well as two convenient
function to get the value out of it (str and get_inner_content) the
first is generic, the second specifically for KernelContent responses
(from AI services).
- AI Service Selector class, has a default, which is based on the order
in the arguments followed by the order in the functions, can be
overridden to implement your own strategy. Closes microsoft#4631
- Introduces ChatHistory and refactors the PromptTemplateConfig. Closes
microsoft#4856, microsoft#4630
- Improves parsing of templates, will now all validate during creation
and throw an error then, instead of some that do not check for validaty
until used.
- Introduces named_args block and thereby the ability to have multiple
arguments for a function call in a template. Closes microsoft#5003

Updates:
- kernel_function decorators, the parameter decorator was removed and
instead we now use Annotated to add a description of a field and we get
the type and required from the function definition.
- core plugins, use the new approach to kernel_function decorators.
- planners, template engines have all been updated to use the kernel and
kernelarguments instead of Context.
- Events have been updated, now use kernelarguments and function_result
- Tokenizers support for named_args and improvements on parsing and
checking.
- Kernel examples and notebooks to use the latest code.
- All unit and integration tests. There is more code coverage now than
before.

Removed:
- kernelContext
- kernel_function_parameter_decorator
- delegate handling code for native functions
- file_io_plugin and tests
- SemanticFunctionConfig
- ChatPromptTemplate

### 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 😄

---------

Co-authored-by: Evan Mattson <evmattso@microsoft.com>
Co-authored-by: Evan Mattson <35585003+moonbox3@users.noreply.github.com>
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
kernel Issues or pull requests impacting the core kernel python Pull requests for the Python Semantic Kernel
Projects
Archived in project
3 participants