feat: rename function to tool in sdk (#2288)

Co-authored-by: Caren Thomas <caren@caren-mac.local>
This commit is contained in:
cthomas
2024-12-19 12:12:58 -08:00
committed by GitHub
parent 5f2ba44e93
commit 7d5be32a59
16 changed files with 202 additions and 164 deletions

View File

@@ -75,6 +75,10 @@ def nb_print(messages):
return_data = json.loads(msg.function_return)
if "message" in return_data and return_data["message"] == "None":
continue
if msg.message_type == "tool_return_message":
return_data = json.loads(msg.tool_return)
if "message" in return_data and return_data["message"] == "None":
continue
title = msg.message_type.replace("_", " ").upper()
html_output += f"""
@@ -94,11 +98,17 @@ def get_formatted_content(msg):
elif msg.message_type == "function_call":
args = format_json(msg.function_call.arguments)
return f'<div class="content"><span class="function-name">{html.escape(msg.function_call.name)}</span>({args})</div>'
elif msg.message_type == "tool_call_message":
args = format_json(msg.tool_call.arguments)
return f'<div class="content"><span class="function-name">{html.escape(msg.function_call.name)}</span>({args})</div>'
elif msg.message_type == "function_return":
return_value = format_json(msg.function_return)
# return f'<div class="status-line">Status: {html.escape(msg.status)}</div><div class="content">{return_value}</div>'
return f'<div class="content">{return_value}</div>'
elif msg.message_type == "tool_return_message":
return_value = format_json(msg.tool_return)
# return f'<div class="status-line">Status: {html.escape(msg.status)}</div><div class="content">{return_value}</div>'
return f'<div class="content">{return_value}</div>'
elif msg.message_type == "user_message":
if is_json(msg.message):
return f'<div class="content">{format_json(msg.message)}</div>'

View File

@@ -2,7 +2,7 @@ import os
import uuid
from letta import create_client
from letta.schemas.letta_message import FunctionCallMessage
from letta.schemas.letta_message import ToolCallMessage
from letta.schemas.tool_rule import ChildToolRule, InitToolRule, TerminalToolRule
from tests.helpers.endpoints_helper import (
assert_invoked_send_message_with_keyword,
@@ -116,9 +116,9 @@ def main():
# 6. Here, we thoroughly check the correctness of the response
tool_names += ["send_message"] # Add send message because we expect this to be called at the end
for m in response.messages:
if isinstance(m, FunctionCallMessage):
if isinstance(m, ToolCallMessage):
# Check that it's equal to the first one
assert m.function_call.name == tool_names[0]
assert m.tool_call.name == tool_names[0]
# Pop out first one
tool_names = tool_names[1:]