fix: Fix composio bugs (#884)

Co-authored-by: Charles Packer <packercharles@gmail.com>
This commit is contained in:
Matthew Zhou
2025-02-03 09:09:45 -10:00
committed by GitHub
parent 7e11d44baf
commit 85dee1785b
2 changed files with 13 additions and 3 deletions

View File

@@ -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

View File

@@ -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: