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: Introduce the chat history reducer #10190

Merged
merged 26 commits into from
Jan 23, 2025
Merged
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
84fabe0
wip: chat history reducer
moonbox3 Jan 13, 2025
8d9102f
Merge branch 'main' into py-chat-history-reduce
moonbox3 Jan 14, 2025
a5b712e
Implement agent chat history reducer. Add unit tests. Add sample.
moonbox3 Jan 15, 2025
14ab2f4
Update readme
moonbox3 Jan 15, 2025
98108bf
Merge branch 'main' into py-chat-history-reduce
moonbox3 Jan 15, 2025
6f132b9
Move chat history reducer to extend chat history. Break circular depe…
moonbox3 Jan 16, 2025
6d4f617
Address PR feedback
moonbox3 Jan 17, 2025
8564f23
Repair uv.lock
moonbox3 Jan 17, 2025
58f1218
Fix uv lock again
moonbox3 Jan 17, 2025
66abe04
Upgrade to uv 0.5.20 locally. Re sync uv lock
moonbox3 Jan 17, 2025
93f788f
Merge branch 'main' into py-chat-history-reduce
moonbox3 Jan 17, 2025
0aebeee
Address PR feedback
moonbox3 Jan 20, 2025
429ddf8
Sample update.
moonbox3 Jan 20, 2025
fdc7af7
Work on chat history reducer.
moonbox3 Jan 21, 2025
8ad615b
Merge main to branch
moonbox3 Jan 21, 2025
e5d5d22
wip on history reducer
moonbox3 Jan 21, 2025
3277e39
wip: instruction role handling
moonbox3 Jan 21, 2025
0002b9a
Final updates to chat history reducer and samples. Update tests.
moonbox3 Jan 22, 2025
daa685c
Improve AzureAI inference instruction role field. Add tests.
moonbox3 Jan 22, 2025
3b11a7e
Merge branch 'main' into py-chat-history-reduce
moonbox3 Jan 22, 2025
58547df
Cleanup
moonbox3 Jan 23, 2025
57b5e04
Merge branch 'main' into py-chat-history-reduce
moonbox3 Jan 23, 2025
4c21cc0
Merge main to branch
moonbox3 Jan 23, 2025
91f72ea
PR feedback
moonbox3 Jan 23, 2025
78065d0
Merge branch 'py-chat-history-reduce' of github.com:moonbox3/semantic…
moonbox3 Jan 23, 2025
307efd8
Update sample to use kernel invoke function call
moonbox3 Jan 23, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
PR feedback
moonbox3 committed Jan 23, 2025
commit 91f72ea2255f116daeb156a6a9f9af8c71436681
Original file line number Diff line number Diff line change
@@ -143,7 +143,7 @@ async def invoke_agent(self, agent: ChatCompletionAgent, chat_history: ChatHisto

# The index is incremented by 2 because the agent is told to:
# "Add one to the latest user number and spell it in Spanish without explanation."
# The agent sends 1, 3, 5, etc., and the agent responds with 2, 4, 6, etc. (in Spanish)
# The user sends 1, 3, 5, etc., and the agent responds with 2, 4, 6, etc. (in Spanish)
index += 2
print(f"@ Message Count: {len(chat_history.messages)}\n")

@@ -176,7 +176,7 @@ async def invoke_chat(self, agent: ChatCompletionAgent, message_count: int):

# The index is incremented by 2 because the agent is told to:
# "Add one to the latest user number and spell it in Spanish without explanation."
# The agent sends 1, 3, 5, etc., and the agent responds with 2, 4, 6, etc. (in Spanish)
# The user sends 1, 3, 5, etc., and the agent responds with 2, 4, 6, etc. (in Spanish)
index += 2

# Retrieve chat messages in descending order (newest first)
Original file line number Diff line number Diff line change
@@ -49,8 +49,6 @@
# Create a chat history object with the system message.
chat_history = ChatHistory(system_message=system_message)

chat_history.add_developer_message("This is a developer message.")

# Create a kernel and register a prompt function.
# The prompt here contains two variables: chat_history and user_input.
# They will be replaced by the kernel with the actual values when the function is invoked.
Original file line number Diff line number Diff line change
@@ -3,8 +3,6 @@
import sys
from abc import ABC, abstractmethod

from semantic_kernel.utils.experimental_decorator import experimental_class

if sys.version < "3.11":
from typing_extensions import Self # pragma: no cover
else:
@@ -13,6 +11,7 @@
from pydantic import Field

from semantic_kernel.contents.chat_history import ChatHistory
from semantic_kernel.utils.experimental_decorator import experimental_class


@experimental_class