From 85dee1785b128b4fe5462360c73f961999d3f2b2 Mon Sep 17 00:00:00 2001 From: Matthew Zhou Date: Mon, 3 Feb 2025 09:09:45 -1000 Subject: [PATCH] fix: Fix composio bugs (#884) Co-authored-by: Charles Packer --- letta/local_llm/utils.py | 8 +++++++- letta/services/tool_manager.py | 8 ++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/letta/local_llm/utils.py b/letta/local_llm/utils.py index f5d54174..21be45c5 100644 --- a/letta/local_llm/utils.py +++ b/letta/local_llm/utils.py @@ -11,8 +11,11 @@ import letta.local_llm.llm_chat_completion_wrappers.configurable_wrapper as conf import letta.local_llm.llm_chat_completion_wrappers.dolphin as dolphin import letta.local_llm.llm_chat_completion_wrappers.llama3 as llama3 import letta.local_llm.llm_chat_completion_wrappers.zephyr as zephyr +from letta.log import get_logger from letta.schemas.openai.chat_completion_request import Tool, ToolCall +logger = get_logger(__name__) + def post_json_auth_request(uri, json_payload, auth_type, auth_key): """Send a POST request with a JSON payload and optional authentication""" @@ -126,8 +129,11 @@ def num_tokens_from_functions(functions: List[dict], model: str = "gpt-4"): function_tokens += 2 if isinstance(v["items"], dict) and "type" in v["items"]: function_tokens += len(encoding.encode(v["items"]["type"])) + elif field == "default": + function_tokens += 2 + function_tokens += len(encoding.encode(str(v["default"]))) else: - warnings.warn(f"num_tokens_from_functions: Unsupported field {field} in function {function}") + logger.warning(f"num_tokens_from_functions: Unsupported field {field} in function {function}") function_tokens += 11 num_tokens += function_tokens diff --git a/letta/services/tool_manager.py b/letta/services/tool_manager.py index 27188f93..211b3e33 100644 --- a/letta/services/tool_manager.py +++ b/letta/services/tool_manager.py @@ -58,11 +58,15 @@ class ToolManager: @enforce_types def create_or_update_composio_tool(self, tool_create: ToolCreate, actor: PydanticUser) -> PydanticTool: - return self.create_or_update_tool(PydanticTool(tool_type=ToolType.EXTERNAL_COMPOSIO, **tool_create.model_dump()), actor) + return self.create_or_update_tool( + PydanticTool(tool_type=ToolType.EXTERNAL_COMPOSIO, name=tool_create.json_schema["name"], **tool_create.model_dump()), actor + ) @enforce_types def create_or_update_langchain_tool(self, tool_create: ToolCreate, actor: PydanticUser) -> PydanticTool: - return self.create_or_update_tool(PydanticTool(tool_type=ToolType.EXTERNAL_LANGCHAIN, **tool_create.model_dump()), actor) + return self.create_or_update_tool( + PydanticTool(tool_type=ToolType.EXTERNAL_LANGCHAIN, name=tool_create.json_schema["name"], **tool_create.model_dump()), actor + ) @enforce_types def create_tool(self, pydantic_tool: PydanticTool, actor: PydanticUser) -> PydanticTool: