Skip to content

Commit 788465c

Browse files
authored
Merge pull request #2901 from pipecat-ai/pk/llmcontext-messages
Add `messages` property to `LLMContext` for usage parity with `OpenAI…
2 parents db934ea + 776a352 commit 788465c

File tree

3 files changed

+15
-17
lines changed

3 files changed

+15
-17
lines changed

CHANGELOG.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
4545
# or
4646
context: OpenAILLMContext
4747

48-
# Reading messages from context
49-
messages = context.messages
50-
5148
## AFTER:
5249

5350
# Context aggregator type
@@ -58,9 +55,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
5855

5956
# Context type
6057
context: LLMContext
61-
62-
# Reading messages from context
63-
messages = context.get_messages()
6458
```
6559

6660
- Added support for `bulbul:v3` model in `SarvamTTSService` and

src/pipecat/processors/aggregators/llm_context.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,28 @@ def __init__(
106106
self._tools: ToolsSchema | NotGiven = LLMContext._normalize_and_validate_tools(tools)
107107
self._tool_choice: LLMContextToolChoice | NotGiven = tool_choice
108108

109+
@property
110+
def messages(self) -> List[LLMContextMessage]:
111+
"""Get the current messages list.
112+
113+
NOTE: This is equivalent to calling `get_messages()` with no filter. If
114+
you want to filter out LLM-specific messages that don't pertain to your
115+
LLM, use `get_messages()` directly.
116+
117+
Returns:
118+
List of conversation messages.
119+
"""
120+
return self.get_messages()
121+
109122
def get_messages(self, llm_specific_filter: Optional[str] = None) -> List[LLMContextMessage]:
110123
"""Get the current messages list.
111124
112125
Args:
113126
llm_specific_filter: Optional filter to return LLM-specific
114127
messages for the given LLM, in addition to the standard
115128
messages. If messages end up being filtered, an error will be
116-
logged.
129+
logged; this is intended to catch accidental use of
130+
incompatible LLM-specific messages.
117131
118132
Returns:
119133
List of conversation messages.

src/pipecat/services/aws/nova_sonic/context.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@
2727
context: AWSNovaSonicLLMContext
2828
# or
2929
context: OpenAILLMContext
30-
31-
# Reading messages from context
32-
messages = context.messages
3330
```
3431
3532
AFTER:
@@ -43,9 +40,6 @@
4340
4441
# Context type
4542
context: LLMContext
46-
47-
# Reading messages from context
48-
messages = context.get_messages()
4943
```
5044
"""
5145

@@ -70,8 +64,6 @@
7064
"context: AWSNovaSonicLLMContext\n"
7165
"# or\n"
7266
"context: OpenAILLMContext\n\n"
73-
"# Reading messages from context\n"
74-
"messages = context.messages\n"
7567
"```\n\n"
7668
"AFTER:\n"
7769
"```\n"
@@ -82,8 +74,6 @@
8274
"frame: LLMContextFrame\n\n"
8375
"# Context type\n"
8476
"context: LLMContext\n\n"
85-
"# Reading messages from context\n"
86-
"messages = context.messages\n"
8777
"```",
8878
DeprecationWarning,
8979
stacklevel=2,

0 commit comments

Comments
 (0)