Spaces:
Sleeping
Sleeping
| from typing import Annotated | |
| from langchain.tools import tool | |
| from datetime import datetime | |
| from pydantic import BaseModel, Field | |
| from typing import Literal | |
| class WeatherInput(BaseModel): | |
| """Input for weather queries.""" | |
| location: str = Field(description="City name or coordinates") | |
| units: Literal["celsius", "fahrenheit"] = Field( | |
| default="celsius", | |
| description="Temperature unit preference" | |
| ) | |
| include_forecast: bool = Field( | |
| default=False, | |
| description="Include 5-day forecast" | |
| ) | |
| def get_weather(location: str, units: str = "celsius", include_forecast: bool = False) -> str: | |
| """Get current weather and optional forecast.""" | |
| temp = 22 if units == "celsius" else 72 | |
| result = f"Current weather in {location}: {temp} degrees {units[0].upper()}" | |
| if include_forecast: | |
| result += "\nNext 5 days: Sunny" | |
| return result | |
| def calculator(expression: str) -> Annotated[float, int, bool]: | |
| """A simple calculator that can evaluate mathematical expressions. | |
| Args: | |
| expression: A mathematical expression to evaluate | |
| """ | |
| return eval(expression) | |
| def get_datetime(): | |
| """Get the current date and time.""" | |
| return datetime.now() | |
| def search_database(query: str, limit: int = 10) -> str: | |
| """Search the customer database for records matching the query. | |
| Args: | |
| query: Search terms to look for | |
| limit: Maximum number of results to return | |
| """ | |
| return f"Found {limit} results for '{query}'" | |