Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.
fix: extra safety checks in the token counter for functions (#2061)
Charles Packer324346db5cd1
diff --git a/letta/local_llm/utils.py b/letta/local_llm/utils.pyindex 9d625e75b..8ded1f829 100644--- a/letta/local_llm/utils.py+++ b/letta/local_llm/utils.py@@ -95,9 +95,12 @@ def num_tokens_from_functions(functions: List[dict], model: str = "gpt-4"):for function in functions:function_tokens = len(encoding.encode(function["name"]))if function["description"]:- function_tokens += len(encoding.encode(function["description"]))+ if not isinstance(function["description"], str):+ warnings.warn(f"Function {function['name']} has non-string description: {function['description']}")+ else:+ function_tokens += len(encoding.encode(function["description"]))else:- raise ValueError(f"Function {function['name']} has no description, function: {function}")+ warnings.warn(f"Function {function['name']} has no description, function: {function}")if "parameters" in function:parameters = function["parameters"]