Merge pull request #2901 from pipecat-ai/pk/llmcontext-messages
Add `messages` property to `LLMContext` for usage parity with `OpenAI…
This commit is contained in:
@@ -45,9 +45,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
# or
|
# or
|
||||||
context: OpenAILLMContext
|
context: OpenAILLMContext
|
||||||
|
|
||||||
# Reading messages from context
|
|
||||||
messages = context.messages
|
|
||||||
|
|
||||||
## AFTER:
|
## AFTER:
|
||||||
|
|
||||||
# Context aggregator type
|
# Context aggregator type
|
||||||
@@ -58,9 +55,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
# Context type
|
# Context type
|
||||||
context: LLMContext
|
context: LLMContext
|
||||||
|
|
||||||
# Reading messages from context
|
|
||||||
messages = context.get_messages()
|
|
||||||
```
|
```
|
||||||
|
|
||||||
- Added support for `bulbul:v3` model in `SarvamTTSService` and
|
- Added support for `bulbul:v3` model in `SarvamTTSService` and
|
||||||
|
|||||||
@@ -106,6 +106,19 @@ class LLMContext:
|
|||||||
self._tools: ToolsSchema | NotGiven = LLMContext._normalize_and_validate_tools(tools)
|
self._tools: ToolsSchema | NotGiven = LLMContext._normalize_and_validate_tools(tools)
|
||||||
self._tool_choice: LLMContextToolChoice | NotGiven = tool_choice
|
self._tool_choice: LLMContextToolChoice | NotGiven = tool_choice
|
||||||
|
|
||||||
|
@property
|
||||||
|
def messages(self) -> List[LLMContextMessage]:
|
||||||
|
"""Get the current messages list.
|
||||||
|
|
||||||
|
NOTE: This is equivalent to calling `get_messages()` with no filter. If
|
||||||
|
you want to filter out LLM-specific messages that don't pertain to your
|
||||||
|
LLM, use `get_messages()` directly.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
List of conversation messages.
|
||||||
|
"""
|
||||||
|
return self.get_messages()
|
||||||
|
|
||||||
def get_messages(self, llm_specific_filter: Optional[str] = None) -> List[LLMContextMessage]:
|
def get_messages(self, llm_specific_filter: Optional[str] = None) -> List[LLMContextMessage]:
|
||||||
"""Get the current messages list.
|
"""Get the current messages list.
|
||||||
|
|
||||||
@@ -113,7 +126,8 @@ class LLMContext:
|
|||||||
llm_specific_filter: Optional filter to return LLM-specific
|
llm_specific_filter: Optional filter to return LLM-specific
|
||||||
messages for the given LLM, in addition to the standard
|
messages for the given LLM, in addition to the standard
|
||||||
messages. If messages end up being filtered, an error will be
|
messages. If messages end up being filtered, an error will be
|
||||||
logged.
|
logged; this is intended to catch accidental use of
|
||||||
|
incompatible LLM-specific messages.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
List of conversation messages.
|
List of conversation messages.
|
||||||
|
|||||||
@@ -27,9 +27,6 @@ including conversation history management and role-specific message processing.
|
|||||||
context: AWSNovaSonicLLMContext
|
context: AWSNovaSonicLLMContext
|
||||||
# or
|
# or
|
||||||
context: OpenAILLMContext
|
context: OpenAILLMContext
|
||||||
|
|
||||||
# Reading messages from context
|
|
||||||
messages = context.messages
|
|
||||||
```
|
```
|
||||||
|
|
||||||
AFTER:
|
AFTER:
|
||||||
@@ -43,9 +40,6 @@ including conversation history management and role-specific message processing.
|
|||||||
|
|
||||||
# Context type
|
# Context type
|
||||||
context: LLMContext
|
context: LLMContext
|
||||||
|
|
||||||
# Reading messages from context
|
|
||||||
messages = context.get_messages()
|
|
||||||
```
|
```
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@@ -70,8 +64,6 @@ with warnings.catch_warnings():
|
|||||||
"context: AWSNovaSonicLLMContext\n"
|
"context: AWSNovaSonicLLMContext\n"
|
||||||
"# or\n"
|
"# or\n"
|
||||||
"context: OpenAILLMContext\n\n"
|
"context: OpenAILLMContext\n\n"
|
||||||
"# Reading messages from context\n"
|
|
||||||
"messages = context.messages\n"
|
|
||||||
"```\n\n"
|
"```\n\n"
|
||||||
"AFTER:\n"
|
"AFTER:\n"
|
||||||
"```\n"
|
"```\n"
|
||||||
@@ -82,8 +74,6 @@ with warnings.catch_warnings():
|
|||||||
"frame: LLMContextFrame\n\n"
|
"frame: LLMContextFrame\n\n"
|
||||||
"# Context type\n"
|
"# Context type\n"
|
||||||
"context: LLMContext\n\n"
|
"context: LLMContext\n\n"
|
||||||
"# Reading messages from context\n"
|
|
||||||
"messages = context.messages\n"
|
|
||||||
"```",
|
"```",
|
||||||
DeprecationWarning,
|
DeprecationWarning,
|
||||||
stacklevel=2,
|
stacklevel=2,
|
||||||
|
|||||||
Reference in New Issue
Block a user