WeByT3 commited on
Commit
96d23bf
·
verified ·
1 Parent(s): 72dac12

Update tools.py

Browse files
Files changed (1) hide show
  1. tools.py +15 -49
tools.py CHANGED
@@ -1,6 +1,5 @@
1
  from langchain_core.tools import tool
2
- import requests
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 get_studio_album_count(artist_name: str, start_year: int, end_year: int) -> dict:
54
  """
55
- Search music APIs for relevant information related to music artists.
56
- It returns a dictionary with the number of albums produced during that interval and the names.
57
-
58
  Args:
59
- artist_name: Name of the artist to search
60
- start_year: The start year for searching information
61
- end_year: The end year for searching information
62
 
63
- Exampe:
64
- {"message": "How many albums did The Beatles produce between 1965 and 1968 ?"}
65
- get_studio_album_count("The Beatles", 1965, 1968)
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
- studio_albums.append({
98
- "title": title,
99
- "release_year": year,
100
- })
101
 
102
- return {
103
- "studio_album_count": len(studio_albums),
104
- "studio_album_list": sorted(studio_albums, key=lambda x: x["release_year"]),
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)}"