From db8780fd9c1f86a2a246960051607e967531fb60 Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Sat, 12 Apr 2025 17:16:27 -0700 Subject: [PATCH] refac: default tool boilerplate --- .../workspace/Tools/ToolkitEditor.svelte | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/lib/components/workspace/Tools/ToolkitEditor.svelte b/src/lib/components/workspace/Tools/ToolkitEditor.svelte index ecfb2144f..37ddaa05d 100644 --- a/src/lib/components/workspace/Tools/ToolkitEditor.svelte +++ b/src/lib/components/workspace/Tools/ToolkitEditor.svelte @@ -50,22 +50,20 @@ let boilerplate = `import os import requests from datetime import datetime - +from pydantic import BaseModel, Field class Tools: def __init__(self): pass # Add your custom tools using pure Python code here, make sure to add type hints - # Use Sphinx-style docstrings to document your tools, they will be used for generating tools specifications - # Please refer to function_calling_filter_pipeline.py file from pipelines project for an example - + def get_user_name_and_email_and_id(self, __user__: dict = {}) -> str: """ Get the user name, Email and ID from the user object. """ - # Do not include :param for __user__ in the docstring as it should not be shown in the tool's specification + # Do not include a descrption for __user__ as it should not be shown in the tool's specification # The session user object will be passed as a parameter when the function is called print(__user__) @@ -86,7 +84,6 @@ class Tools: def get_current_time(self) -> str: """ Get the current time in a more human-readable format. - :return: The current time. """ now = datetime.now() @@ -97,10 +94,14 @@ class Tools: return f"Current Date and Time = {current_date}, {current_time}" - def calculator(self, equation: str) -> str: + def calculator( + self, + equation: str = Field( + ..., description="The mathematical equation to calculate." + ), + ) -> str: """ Calculate the result of an equation. - :param equation: The equation to calculate. """ # Avoid using eval in production code @@ -112,12 +113,16 @@ class Tools: print(e) return "Invalid equation" - def get_current_weather(self, city: str) -> str: + def get_current_weather( + self, + city: str = Field( + "New York, NY", description="Get the current weather for a given city." + ), + ) -> str: """ Get the current weather for a given city. - :param city: The name of the city to get the weather for. - :return: The current weather information or an error message. """ + api_key = os.getenv("OPENWEATHER_API_KEY") if not api_key: return (