Spaces:
Sleeping
Sleeping
Update tools.py
Browse files
tools.py
CHANGED
|
@@ -1,6 +1,5 @@
|
|
| 1 |
from langchain_core.tools import tool
|
| 2 |
-
import
|
| 3 |
-
from datetime import datetime
|
| 4 |
|
| 5 |
|
| 6 |
@tool
|
|
@@ -50,56 +49,23 @@ def divide(a: int, b: int) -> int:
|
|
| 50 |
return a / b
|
| 51 |
|
| 52 |
@tool
|
| 53 |
-
def
|
| 54 |
"""
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
Args:
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
end_year: The end year for searching information
|
| 62 |
|
| 63 |
-
|
| 64 |
-
{"message": "How many albums did
|
| 65 |
-
|
| 66 |
"""
|
| 67 |
-
# Step 1: Get artist MBID
|
| 68 |
-
search_url = f"https://musicbrainz.org/ws/2/artist/?query=artist:{artist_name}&fmt=json"
|
| 69 |
-
artist_resp = requests.get(search_url).json()
|
| 70 |
-
if not artist_resp["artists"]:
|
| 71 |
-
return {"error": f"Artist '{artist_name}' not found."}
|
| 72 |
-
|
| 73 |
-
artist_mbid = artist_resp["artists"][0]["id"]
|
| 74 |
-
|
| 75 |
-
# Step 2: Get release-groups (albums)
|
| 76 |
-
album_url = f"https://musicbrainz.org/ws/2/release-group?artist={artist_mbid}&type=album&fmt=json&limit=100"
|
| 77 |
-
albums_resp = requests.get(album_url).json()
|
| 78 |
-
|
| 79 |
-
studio_albums = []
|
| 80 |
-
for release_group in albums_resp.get("release-groups", []):
|
| 81 |
-
title = release_group.get("title", "")
|
| 82 |
-
first_date = release_group.get("first-release-date", "")
|
| 83 |
-
|
| 84 |
-
# Filter by date
|
| 85 |
-
try:
|
| 86 |
-
year = int(first_date[:4])
|
| 87 |
-
except:
|
| 88 |
-
continue
|
| 89 |
-
if not (start_year <= year <= end_year):
|
| 90 |
-
continue
|
| 91 |
-
|
| 92 |
-
# Filter out secondary types (e.g. Live, Compilation)
|
| 93 |
-
secondary_types = release_group.get("secondary-types", [])
|
| 94 |
-
if secondary_types:
|
| 95 |
-
continue # Not a studio album
|
| 96 |
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
})
|
| 101 |
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
"
|
| 105 |
-
}
|
|
|
|
| 1 |
from langchain_core.tools import tool
|
| 2 |
+
import wikipediaapi
|
|
|
|
| 3 |
|
| 4 |
|
| 5 |
@tool
|
|
|
|
| 49 |
return a / b
|
| 50 |
|
| 51 |
@tool
|
| 52 |
+
def search_wikipedia(page_title: str, language: str) -> str:
|
| 53 |
"""
|
| 54 |
+
This tool allows searching wikipedia for information on a specific topic. It will return the resulting information in HTML format
|
| 55 |
+
|
|
|
|
| 56 |
Args:
|
| 57 |
+
page_title: The page title to search for
|
| 58 |
+
language: The language for searching the content. For example, "en" for english, "es" for spanish, "fr" for french, etc.
|
|
|
|
| 59 |
|
| 60 |
+
Example:
|
| 61 |
+
{"message": "How many albums did Juanes produce between 2000 and 2005 ?"}
|
| 62 |
+
search_wikipedia("Juanes", "es")
|
| 63 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
|
| 65 |
+
try:
|
| 66 |
+
wiki_wiki = wikipediaapi.Wikipedia('AIAgent (gabriel_abilleira@tutanota.com)', language, extract_format=wikipediaapi.ExtractFormat.HTML)
|
| 67 |
+
page = wiki_wiki.page(page_title)
|
|
|
|
| 68 |
|
| 69 |
+
return f"Title: {page.title}\n\n{page.text}"
|
| 70 |
+
except Exception as e:
|
| 71 |
+
return f"Error: {str(e)}"
|
|
|