refac: default tool boilerplate

This commit is contained in:
Timothy Jaeryang Baek 2025-04-12 17:16:27 -07:00
parent 0a69db291d
commit db8780fd9c

View File

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