From aafb2db62058d031d145e3f5de996b7176e1eeb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleix=20Conchillo=20Flaqu=C3=A9?= Date: Mon, 3 Feb 2025 09:15:24 -0800 Subject: [PATCH] GatedOpenAILLMContextAggregator: use keyword argument and add start_open --- CHANGELOG.md | 3 +++ .../processors/aggregators/gated_openai_llm_context.py | 9 +++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 73e188ced..7ef8af2b3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -47,6 +47,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +- `GatedOpenAILLMContextAggregator` now require keyword arguments. Also, a new + `start_open` argument has been added to set the initial state of the gate. + - Added `organization` and `project` level authentication to `OpenAILLMService`. diff --git a/src/pipecat/processors/aggregators/gated_openai_llm_context.py b/src/pipecat/processors/aggregators/gated_openai_llm_context.py index 8c3f496eb..f3ae78121 100644 --- a/src/pipecat/processors/aggregators/gated_openai_llm_context.py +++ b/src/pipecat/processors/aggregators/gated_openai_llm_context.py @@ -16,9 +16,10 @@ class GatedOpenAILLMContextAggregator(FrameProcessor): """ - def __init__(self, notifier: BaseNotifier, **kwargs): + def __init__(self, *, notifier: BaseNotifier, start_open: bool = False, **kwargs): super().__init__(**kwargs) self._notifier = notifier + self._start_open = start_open self._last_context_frame = None async def process_frame(self, frame: Frame, direction: FrameDirection): @@ -31,7 +32,11 @@ class GatedOpenAILLMContextAggregator(FrameProcessor): await self._stop() await self.push_frame(frame) elif isinstance(frame, OpenAILLMContextFrame): - self._last_context_frame = frame + if self._start_open: + self._start_open = False + await self.push_frame(frame, direction) + else: + self._last_context_frame = frame else: await self.push_frame(frame, direction)