Merge pull request #384 from pipecat-ai/aleix/enable-prompt-caching-frames
services(anthropic): allow setting enable prompt caching via frame
This commit is contained in:
@@ -186,6 +186,13 @@ class LLMSetToolsFrame(DataFrame):
|
||||
tools: List[dict]
|
||||
|
||||
|
||||
@dataclass
|
||||
class LLMEnablePromptCachingFrame(DataFrame):
|
||||
"""A frame to enable/disable prompt caching in certain LLMs.
|
||||
"""
|
||||
enable: bool
|
||||
|
||||
|
||||
@dataclass
|
||||
class TTSSpeakFrame(DataFrame):
|
||||
"""A frame that contains a text that should be spoken by the TTS in the
|
||||
|
||||
@@ -16,6 +16,7 @@ import re
|
||||
|
||||
from pipecat.frames.frames import (
|
||||
Frame,
|
||||
LLMEnablePromptCachingFrame,
|
||||
LLMModelUpdateFrame,
|
||||
TextFrame,
|
||||
VisionImageRawFrame,
|
||||
@@ -62,10 +63,10 @@ class AnthropicContextAggregatorPair:
|
||||
_user: 'AnthropicUserContextAggregator'
|
||||
_assistant: 'AnthropicAssistantContextAggregator'
|
||||
|
||||
def user(self) -> str:
|
||||
def user(self) -> 'AnthropicUserContextAggregator':
|
||||
return self._user
|
||||
|
||||
def assistant(self) -> str:
|
||||
def assistant(self) -> 'AnthropicAssistantContextAggregator':
|
||||
return self._assistant
|
||||
|
||||
|
||||
@@ -227,6 +228,9 @@ class AnthropicLLMService(LLMService):
|
||||
elif isinstance(frame, LLMModelUpdateFrame):
|
||||
logger.debug(f"Switching LLM model to: [{frame.model}]")
|
||||
self._model = frame.model
|
||||
elif isinstance(frame, LLMEnablePromptCachingFrame):
|
||||
logger.debug(f"Setting enable prompt caching to: [{frame.enable}]")
|
||||
self._enable_prompt_caching_beta = frame.enable
|
||||
else:
|
||||
await self.push_frame(frame, direction)
|
||||
|
||||
|
||||
@@ -229,10 +229,10 @@ class OpenAIContextAggregatorPair:
|
||||
_user: 'OpenAIUserContextAggregator'
|
||||
_assistant: 'OpenAIAssistantContextAggregator'
|
||||
|
||||
def user(self) -> str:
|
||||
def user(self) -> 'OpenAIUserContextAggregator':
|
||||
return self._user
|
||||
|
||||
def assistant(self) -> str:
|
||||
def assistant(self) -> 'OpenAIAssistantContextAggregator':
|
||||
return self._assistant
|
||||
|
||||
|
||||
|
||||
@@ -49,10 +49,10 @@ class TogetherContextAggregatorPair:
|
||||
_user: 'TogetherUserContextAggregator'
|
||||
_assistant: 'TogetherAssistantContextAggregator'
|
||||
|
||||
def user(self) -> str:
|
||||
def user(self) -> 'TogetherUserContextAggregator':
|
||||
return self._user
|
||||
|
||||
def assistant(self) -> str:
|
||||
def assistant(self) -> 'TogetherAssistantContextAggregator':
|
||||
return self._assistant
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user