-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
.Net: Added IChatHistoryReducer for ChatCompletion with AzureOpenAI and OpenAI #8894
Open
sandrohanea
wants to merge
6
commits into
microsoft:main
Choose a base branch
from
sandrohanea:sandrohanea/chat-history-reducer
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
.Net: Added IChatHistoryReducer for ChatCompletion with AzureOpenAI and OpenAI #8894
sandrohanea
wants to merge
6
commits into
microsoft:main
from
sandrohanea:sandrohanea/chat-history-reducer
+442
−62
Conversation
This file contains 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
markwallace-microsoft
added
.NET
Issue or Pull requests regarding .NET code
kernel
Issues or pull requests impacting the core kernel
kernel.core
labels
Sep 18, 2024
github-actions
bot
changed the title
Added IChatHistoryReducer for ChatCompletion with AzureOpenAI and OpenAI
.Net: Added IChatHistoryReducer for ChatCompletion with AzureOpenAI and OpenAI
Sep 18, 2024
sandrohanea
had a problem deploying
to
integration
September 18, 2024 13:54
— with
GitHub Actions
Failure
sandrohanea
temporarily deployed
to
integration
September 18, 2024 14:01
— with
GitHub Actions
Inactive
sandrohanea
temporarily deployed
to
integration
September 18, 2024 14:33
— with
GitHub Actions
Inactive
sandrohanea
temporarily deployed
to
integration
September 18, 2024 14:59
— with
GitHub Actions
Inactive
crickman
reviewed
Sep 18, 2024
dotnet/src/SemanticKernel.Abstractions/AI/ChatCompletion/ChatHistoryReducerExtensions.cs
Outdated
Show resolved
Hide resolved
sandrohanea
temporarily deployed
to
integration
September 18, 2024 15:22
— with
GitHub Actions
Inactive
Would it make sense to provide both implementations of the reducer in the core framework:
|
sandrohanea
temporarily deployed
to
integration
September 18, 2024 15:47
— with
GitHub Actions
Inactive
dotnet/src/SemanticKernel.Abstractions/AI/ChatCompletion/ChatHistoryReducerExtensions.cs
Show resolved
Hide resolved
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
kernel.core
kernel
Issues or pull requests impacting the core kernel
.NET
Issue or Pull requests regarding .NET code
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
When using Auto-Invocation for Tools with OpenAI and AzureOpenAI, there is no way to intercept and reduce the chat history after tools are being invoked.
This is needed as some tools might return long responses and we might want to execute different prompt compression / optimization based on the tool result.
Note:
AutoFunctionInvocationFilters
cannot be used as they are invoked only before the result of the tools is added to the chat history.The alternative to this approach would be to intercept the http call to Open AI and alter the request directly but that will cause multiple allocation, serializations and deserializations and won't scale to other Connectors.
Description
This change is extracting
IChatHistoryReducer
fromAgents.Core
project and moving it to SK.Abstrations.AI.ChatCompletions.IChatHistoryReducer
was renamed toIAgentChatHistoryReducer
in order to avoid confusion as it requires 2 more methods:Equals
andGetHashCode
that are used to compute the agent channel key. It now inheritsIChatHistoryReducer
.Added tests to ensure that a DI registered reducer is used in the ChatCompletionService of both OpenAI and AzureOpenAI connectors.
Important notice: the reducer is not mutating the
ChatHistory
, as it might be that new tool invocation or chat turns will require different reducing logic. (e.g. context-aware summarization)Contribution Checklist