Spaces:
Sleeping
Sleeping
Update tools.py
Browse files
tools.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
from langchain_core.tools import tool
|
| 2 |
import pandas as pd
|
| 3 |
import os
|
|
|
|
| 4 |
|
| 5 |
|
| 6 |
@tool
|
|
@@ -47,4 +48,22 @@ def divide(a: int, b: int) -> int:
|
|
| 47 |
"""
|
| 48 |
if b == 0:
|
| 49 |
raise ValueError("Cannot divide by zero.")
|
| 50 |
-
return a / b
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from langchain_core.tools import tool
|
| 2 |
import pandas as pd
|
| 3 |
import os
|
| 4 |
+
import wikipedia
|
| 5 |
|
| 6 |
|
| 7 |
@tool
|
|
|
|
| 48 |
"""
|
| 49 |
if b == 0:
|
| 50 |
raise ValueError("Cannot divide by zero.")
|
| 51 |
+
return a / b
|
| 52 |
+
|
| 53 |
+
@tool
|
| 54 |
+
def wikipedia_search_tool(query: str) -> str:
|
| 55 |
+
"""
|
| 56 |
+
Search wikipedia for articles
|
| 57 |
+
|
| 58 |
+
Args:
|
| 59 |
+
query: The query to search in wikipedia
|
| 60 |
+
|
| 61 |
+
Example:
|
| 62 |
+
wikipedia_search_tool("How many albums did the Beatles produce between 1965 and 1968?")
|
| 63 |
+
"""
|
| 64 |
+
try:
|
| 65 |
+
page_title = wikipedia.search(query)[0]
|
| 66 |
+
summary = wikipedia.summary(page_title, sentences=5)
|
| 67 |
+
return f"Page Title: {page_title}\n\n{summary}"
|
| 68 |
+
except Exception as e:
|
| 69 |
+
return f"Error: {str(e)}"
|