mirror of
https://github.com/open-webui/open-webui
synced 2025-06-08 15:37:22 +00:00
refac: default tool boilerplate
This commit is contained in:
parent
0a69db291d
commit
db8780fd9c
@ -50,22 +50,20 @@
|
|||||||
let boilerplate = `import os
|
let boilerplate = `import os
|
||||||
import requests
|
import requests
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
from pydantic import BaseModel, Field
|
||||||
|
|
||||||
class Tools:
|
class Tools:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# Add your custom tools using pure Python code here, make sure to add type hints
|
# 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:
|
def get_user_name_and_email_and_id(self, __user__: dict = {}) -> str:
|
||||||
"""
|
"""
|
||||||
Get the user name, Email and ID from the user object.
|
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
|
# The session user object will be passed as a parameter when the function is called
|
||||||
|
|
||||||
print(__user__)
|
print(__user__)
|
||||||
@ -86,7 +84,6 @@ class Tools:
|
|||||||
def get_current_time(self) -> str:
|
def get_current_time(self) -> str:
|
||||||
"""
|
"""
|
||||||
Get the current time in a more human-readable format.
|
Get the current time in a more human-readable format.
|
||||||
:return: The current time.
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
now = datetime.now()
|
now = datetime.now()
|
||||||
@ -97,10 +94,14 @@ class Tools:
|
|||||||
|
|
||||||
return f"Current Date and Time = {current_date}, {current_time}"
|
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.
|
Calculate the result of an equation.
|
||||||
:param equation: The equation to calculate.
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Avoid using eval in production code
|
# Avoid using eval in production code
|
||||||
@ -112,12 +113,16 @@ class Tools:
|
|||||||
print(e)
|
print(e)
|
||||||
return "Invalid equation"
|
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.
|
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")
|
api_key = os.getenv("OPENWEATHER_API_KEY")
|
||||||
if not api_key:
|
if not api_key:
|
||||||
return (
|
return (
|
||||||
|
Loading…
Reference in New Issue
Block a user