feat: add token column to mcp_servers and pipe through to sse server config (#2775)

Co-authored-by: Jin Peng <jinjpeng@Jins-MacBook-Pro.local>
This commit is contained in:
jnjpng
2025-06-14 18:48:10 -07:00
committed by GitHub
parent c71a6d1917
commit 729acaedb2
13 changed files with 310 additions and 42 deletions

View File

@@ -100,7 +100,11 @@ def num_tokens_from_functions(functions: List[dict], model: str = "gpt-4"):
try:
if field == "type":
function_tokens += 2
function_tokens += len(encoding.encode(v["type"]))
# Handle both string and array types, e.g. {"type": ["string", "null"]}
if isinstance(v["type"], list):
function_tokens += len(encoding.encode(",".join(v["type"])))
else:
function_tokens += len(encoding.encode(v["type"]))
elif field == "description":
function_tokens += 2
function_tokens += len(encoding.encode(v["description"]))