-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
moving unbounded buffered chat to a different file
- Loading branch information
1 parent
3b22a72
commit 1966d7e
Showing
3 changed files
with
35 additions
and
37 deletions.
There are no files selected for viewing
8 changes: 4 additions & 4 deletions
8
python/packages/autogen-core/src/autogen_core/model_context/__init__.py
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
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
31 changes: 31 additions & 0 deletions
31
...utogen-core/src/autogen_core/model_context/_unbounded_buffered_chat_completion_context.py
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from typing import Any, List, Mapping | ||
|
||
from ..models import LLMMessage | ||
from ._chat_completion_context import ChatCompletionContext | ||
|
||
|
||
class UnboundedBufferedChatCompletionContext(ChatCompletionContext): | ||
"""An unbounded buffered chat completion context that keeps a view of the all the messages.""" | ||
|
||
def __init__(self, initial_messages: List[LLMMessage] | None = None) -> None: | ||
self._messages: List[LLMMessage] = initial_messages or [] | ||
|
||
async def add_message(self, message: LLMMessage) -> None: | ||
"""Add a message to the memory.""" | ||
self._messages.append(message) | ||
|
||
async def get_messages(self) -> List[LLMMessage]: | ||
"""Get at most `buffer_size` recent messages.""" | ||
return self._messages | ||
|
||
async def clear(self) -> None: | ||
"""Clear the message memory.""" | ||
self._messages = [] | ||
|
||
def save_state(self) -> Mapping[str, Any]: | ||
return { | ||
"messages": [message for message in self._messages], | ||
} | ||
|
||
def load_state(self, state: Mapping[str, Any]) -> None: | ||
self._messages = state["messages"] |