llm_response: add some initial docstrings to LLM aggregators
This commit is contained in:
@@ -36,33 +36,51 @@ from pipecat.processors.frame_processor import FrameDirection, FrameProcessor
|
|||||||
|
|
||||||
|
|
||||||
class BaseLLMResponseAggregator(FrameProcessor):
|
class BaseLLMResponseAggregator(FrameProcessor):
|
||||||
|
"""This is the base class for all LLM response aggregators. These
|
||||||
|
aggregators process incoming frames and aggregate content until they are
|
||||||
|
ready to push the aggregation. In the case of a user, an aggregation might
|
||||||
|
be a full transcription received from the STT service.
|
||||||
|
|
||||||
|
The LLM response aggregators also keep a store (e.g. a message list or an
|
||||||
|
LLM context) of the current conversation, that is, it stores the messages
|
||||||
|
said by the user or by the bot.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
super().__init__(**kwargs)
|
super().__init__(**kwargs)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def messages(self) -> List[dict]:
|
def messages(self) -> List[dict]:
|
||||||
|
"""Returns the messages from the current conversation."""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def role(self) -> str:
|
def role(self) -> str:
|
||||||
|
"""Returns the role (e.g. user, assistant...) for this aggregator."""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def add_messages(self, messages):
|
def add_messages(self, messages):
|
||||||
|
"""Add the given messages to the conversation."""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def set_messages(self, messages):
|
def set_messages(self, messages):
|
||||||
|
"""Reset the conversation with the given messages."""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def set_tools(self, tools):
|
def set_tools(self, tools):
|
||||||
|
"""Set LLM tools to be used in the current conversation."""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def reset(self):
|
def reset(self):
|
||||||
|
"""Reset the internals of this aggregator. This should not modify the
|
||||||
|
internal messages."""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
@@ -71,6 +89,12 @@ class BaseLLMResponseAggregator(FrameProcessor):
|
|||||||
|
|
||||||
|
|
||||||
class LLMResponseAggregator(BaseLLMResponseAggregator):
|
class LLMResponseAggregator(BaseLLMResponseAggregator):
|
||||||
|
"""This is a base LLM aggregator that uses a simple list of messages to
|
||||||
|
store the conversation. It pushes `LLMMessagesFrame` as an aggregation
|
||||||
|
frame.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
*,
|
*,
|
||||||
@@ -122,6 +146,11 @@ class LLMResponseAggregator(BaseLLMResponseAggregator):
|
|||||||
|
|
||||||
|
|
||||||
class LLMContextResponseAggregator(BaseLLMResponseAggregator):
|
class LLMContextResponseAggregator(BaseLLMResponseAggregator):
|
||||||
|
"""This is a base LLM aggregator that uses an LLM context to store the
|
||||||
|
conversation. It pushes `OpenAILLMContextFrame` as an aggregation frame.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
def __init__(self, *, context: OpenAILLMContext, role: str, **kwargs):
|
def __init__(self, *, context: OpenAILLMContext, role: str, **kwargs):
|
||||||
super().__init__(**kwargs)
|
super().__init__(**kwargs)
|
||||||
self._context = context
|
self._context = context
|
||||||
@@ -173,6 +202,14 @@ class LLMContextResponseAggregator(BaseLLMResponseAggregator):
|
|||||||
|
|
||||||
|
|
||||||
class LLMUserContextAggregator(LLMContextResponseAggregator):
|
class LLMUserContextAggregator(LLMContextResponseAggregator):
|
||||||
|
"""This is a user LLM aggregator that uses an LLM context to store the
|
||||||
|
conversation. It aggregates transcriptions from the STT service and it has
|
||||||
|
logic to handle multiple scenarios where transcriptions are received between
|
||||||
|
VAD events (`UserStartedSpeakingFrame` and `UserStoppedSpeakingFrame`) or
|
||||||
|
even outside or no VAD events at all.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
context: OpenAILLMContext,
|
context: OpenAILLMContext,
|
||||||
@@ -289,6 +326,12 @@ class LLMUserContextAggregator(LLMContextResponseAggregator):
|
|||||||
|
|
||||||
|
|
||||||
class LLMAssistantContextAggregator(LLMContextResponseAggregator):
|
class LLMAssistantContextAggregator(LLMContextResponseAggregator):
|
||||||
|
"""This is an assistant LLM aggregator that uses an LLM context to store the
|
||||||
|
conversation. It aggregates text frames received between
|
||||||
|
`LLMFullResponseStartFrame` and `LLMFullResponseEndFrame`.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
def __init__(self, context: OpenAILLMContext, *, expect_stripped_words: bool = True, **kwargs):
|
def __init__(self, context: OpenAILLMContext, *, expect_stripped_words: bool = True, **kwargs):
|
||||||
super().__init__(context=context, role="assistant", **kwargs)
|
super().__init__(context=context, role="assistant", **kwargs)
|
||||||
self._expect_stripped_words = expect_stripped_words
|
self._expect_stripped_words = expect_stripped_words
|
||||||
|
|||||||
Reference in New Issue
Block a user