Spaces:
Sleeping
Sleeping
| from langchain_core.tools import tool | |
| from langchain_community.tools.tavily_search import TavilySearchResults | |
| 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 substract(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 web_search(query: str) -> str: | |
| """Search Tavily for a query and return maximum 3 results. | |
| Args: | |
| query: The search query.""" | |
| search_docs = TavilySearchResults(max_results=3).invoke(query=query) | |
| formatted_search_docs = "\n\n---\n\n".join( | |
| [ | |
| f'<Document source="{doc.metadata["source"]}" page="{doc.metadata.get("page", "")}"/>\n{doc.page_content}\n</Document>' | |
| for doc in search_docs | |
| ]) | |
| return {"web_results": formatted_search_docs} |