Spaces:
Sleeping
Sleeping
| from langchain_core.tools import tool | |
| import pandas as pd | |
| import os | |
| import wikipedia | |
| def add(a: int, b: int) -> int: | |
| """ | |
| Sums two values and returns the result of the sum | |
| Args: | |
| a: first number | |
| b: second number | |
| """ | |
| return a + b | |
| def subtract(a: int, b: int) -> int: | |
| """ | |
| Subtracts one value from another and returns the result of the sum | |
| Args: | |
| a: first number | |
| b: second number | |
| """ | |
| return a - b | |
| def multiply(a: int, b: int) -> int: | |
| """ | |
| Multiplies two values and returns the result of the sum | |
| Args: | |
| a: first number | |
| b: second number | |
| """ | |
| return a * b | |
| def divide(a: int, b: int) -> int: | |
| """ | |
| Divides two values and returns the result of the sum | |
| Args: | |
| a: numerator | |
| b: denominator | |
| """ | |
| if b == 0: | |
| raise ValueError("Cannot divide by zero.") | |
| return a / b | |
| def wikipedia_search_tool(query: str) -> str: | |
| """ | |
| Search wikipedia for articles | |
| Args: | |
| query: The query to search in wikipedia | |
| Example: | |
| wikipedia_search_tool("How many albums did the Beatles produce between 1965 and 1968?") | |
| """ | |
| try: | |
| page_title = wikipedia.search(query)[0] | |
| summary = wikipedia.summary(page_title, sentences=5) | |
| return f"Page Title: {page_title}\n\n{summary}" | |
| except Exception as e: | |
| return f"Error: {str(e)}" |