From 40fe4ce6fb37812c09fec452d94d181665d93733 Mon Sep 17 00:00:00 2001 From: Aashraya Date: Wed, 21 Aug 2024 15:49:36 +0530 Subject: [PATCH 1/2] handle empty parameters for anthropic function calling --- src/pipecat/services/anthropic.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/pipecat/services/anthropic.py b/src/pipecat/services/anthropic.py index 899b9c174..a87cc768e 100644 --- a/src/pipecat/services/anthropic.py +++ b/src/pipecat/services/anthropic.py @@ -171,7 +171,8 @@ class AnthropicLLMService(LLMService): await self.call_function(context=context, tool_call_id=tool_use_block.id, function_name=tool_use_block.name, - arguments=json.loads(json_accumulator)) + arguments=json.loads(json_accumulator) if json_accumulator else dict() + ) # Calculate usage. Do this here in its own if statement, because there may be usage # data embedded in messages that we do other processing for, above. From ec6063ecc497e6092ab9672fabc0f89d5c50fe85 Mon Sep 17 00:00:00 2001 From: Aashraya Date: Wed, 21 Aug 2024 16:31:50 +0530 Subject: [PATCH 2/2] system is not a list, it is handled and assisgned as string --- src/pipecat/services/anthropic.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pipecat/services/anthropic.py b/src/pipecat/services/anthropic.py index a87cc768e..329959b1f 100644 --- a/src/pipecat/services/anthropic.py +++ b/src/pipecat/services/anthropic.py @@ -43,7 +43,7 @@ from pipecat.processors.aggregators.llm_response import ( from loguru import logger try: - from anthropic import AsyncAnthropic + from anthropic import AsyncAnthropic, NOT_GIVEN, NotGiven except ModuleNotFoundError as e: logger.error(f"Exception: {e}") logger.error( @@ -135,7 +135,7 @@ class AnthropicLLMService(LLMService): response = await api_call( tools=context.tools or [], - system=context.system or [], + system=context.system, messages=messages, model=self._model, max_tokens=self._max_tokens, @@ -270,7 +270,7 @@ class AnthropicLLMContext(OpenAILLMContext): tools: list[dict] | None = None, tool_choice: dict | None = None, *, - system: List | None = None + system: str | NotGiven = NOT_GIVEN ): super().__init__(messages=messages, tools=tools, tool_choice=tool_choice) self._user_image_request_context = {}