diff --git a/linux-py3.10-requirements.txt b/linux-py3.10-requirements.txt index 7b42fd5e3..dd9969964 100644 --- a/linux-py3.10-requirements.txt +++ b/linux-py3.10-requirements.txt @@ -16,7 +16,7 @@ aiosignal==1.3.1 # via aiohttp annotated-types==0.7.0 # via pydantic -anthropic==0.28.1 +anthropic==0.34.0 # via # openpipe # pipecat-ai (pyproject.toml) diff --git a/macos-py3.10-requirements.txt b/macos-py3.10-requirements.txt index a764e62d4..c94f6e41a 100644 --- a/macos-py3.10-requirements.txt +++ b/macos-py3.10-requirements.txt @@ -16,7 +16,7 @@ aiosignal==1.3.1 # via aiohttp annotated-types==0.7.0 # via pydantic -anthropic==0.28.1 +anthropic==0.34.0 # via # openpipe # pipecat-ai (pyproject.toml) diff --git a/src/pipecat/services/anthropic.py b/src/pipecat/services/anthropic.py index bfe2e86f1..7974bd3e0 100644 --- a/src/pipecat/services/anthropic.py +++ b/src/pipecat/services/anthropic.py @@ -206,10 +206,13 @@ class AnthropicLLMService(LLMService): finally: await self.stop_processing_metrics() await self.push_frame(LLMFullResponseEndFrame()) + comp_tokens = completion_tokens if not use_completion_tokens_estimate else completion_tokens_estimate await self._report_usage_metrics( prompt_tokens=prompt_tokens, - completion_tokens=(completion_tokens if not use_completion_tokens_estimate - else completion_tokens_estimate)) + completion_tokens=comp_tokens, + cache_creation_input_tokens=cache_creation_input_tokens, + cache_read_input_tokens=cache_read_input_tokens + ) async def process_frame(self, frame: Frame, direction: FrameDirection): await super().process_frame(frame, direction) @@ -244,13 +247,20 @@ class AnthropicLLMService(LLMService): def _estimate_tokens(self, text: str) -> int: return int(len(re.split(r'[^\w]+', text)) * 1.3) - async def _report_usage_metrics(self, prompt_tokens: int, completion_tokens: int): - if prompt_tokens or completion_tokens: + async def _report_usage_metrics( + self, + prompt_tokens: int, + completion_tokens: int, + cache_creation_input_tokens: int, + cache_read_input_tokens: int): + if prompt_tokens or completion_tokens or cache_creation_input_tokens or cache_read_input_tokens: tokens = { "processor": self.name, "model": self._model, "prompt_tokens": prompt_tokens, "completion_tokens": completion_tokens, + "cache_creation_input_tokens": cache_creation_input_tokens, + "cache_read_input_tokens": cache_read_input_tokens, "total_tokens": prompt_tokens + completion_tokens } await self.start_llm_usage_metrics(tokens)