autogen_core.model_context._unbounded_chat_completion_context 源代码
from typing import List
from pydantic import BaseModel
from typing_extensions import Self
from .._component_config import Component
from ..models import LLMMessage
from ._chat_completion_context import ChatCompletionContext
class UnboundedChatCompletionContextConfig(BaseModel):
initial_messages: List[LLMMessage] | None = None
[文档]
class UnboundedChatCompletionContext(ChatCompletionContext, Component[UnboundedChatCompletionContextConfig]):
"""一个无限制的聊天完成上下文,保持对所有消息的视图。"""
component_config_schema = UnboundedChatCompletionContextConfig
component_provider_override = "autogen_core.model_context.UnboundedChatCompletionContext"
[文档]
async def get_messages(self) -> List[LLMMessage]:
"""获取最多`buffer_size`条最近的消息。"""
return self._messages
[文档]
def _to_config(self) -> UnboundedChatCompletionContextConfig:
return UnboundedChatCompletionContextConfig(initial_messages=self._initial_messages)
[文档]
@classmethod
def _from_config(cls, config: UnboundedChatCompletionContextConfig) -> Self:
return cls(initial_messages=config.initial_messages)