-
-
Save shricodev/422b04f2eac96c77a3210adaea1a1a9c to your computer and use it in GitHub Desktop.
Custom local tools to test Ministral 3 3B tool calling
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os | |
| from datetime import datetime | |
| from pydantic import Field | |
| class Tools: | |
| def __init__(self): | |
| pass | |
| 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 a description 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__) | |
| result = "" | |
| if "name" in __user__: | |
| result += f"User: {__user__['name']}" | |
| if "id" in __user__: | |
| result += f" (ID: {__user__['id']})" | |
| if "email" in __user__: | |
| result += f" (Email: {__user__['email']})" | |
| if result == "": | |
| result = "User: Unknown" | |
| return result | |
| def get_current_time(self) -> str: | |
| """ | |
| Get the current time in a more human-readable format. | |
| """ | |
| now = datetime.now() | |
| current_time = now.strftime("%I:%M:%S %p") | |
| current_date = now.strftime("%A, %B %d, %Y") | |
| return f"Current Date and Time = {current_date}, {current_time}" | |
| def calculator( | |
| self, | |
| equation: str = Field(..., description="The mathematical equation to calculate."), | |
| ) -> str: | |
| """ | |
| Calculate the result of an equation. | |
| """ | |
| try: | |
| result = eval(equation) | |
| return f"{equation} = {result}" | |
| except Exception as e: | |
| print(e) | |
| return "Invalid equation" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment