Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add spotify #48

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bmtools/tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from . import gradio_tools
from . import travel
from . import walmart
from . import spotify


from .tool import Tool
Expand Down
7 changes: 7 additions & 0 deletions bmtools/tools/spotify/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

from ..registry import register

@register("spotify")
def spotify():
from .api import build_tool
return build_tool
47 changes: 47 additions & 0 deletions bmtools/tools/spotify/api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import requests
import json
from datetime import date, datetime, timedelta
import os
from ..tool import Tool

from typing import Optional, Dict, Union, List


def build_tool(config) -> Tool:
tool = Tool(
"Spotify",
"Search over millions of songs & podcasts, artists, albums, playlists and more.",
name_for_model="Spotify",
description_for_model="Plugin for looking up songs & podcasts, artists, albums, playlists and more.",
logo_url="https://your-app-url.com/.well-known/logo.png",
contact_email="hello@contact.com",
legal_info_url="hello@legal.com"
)

BASE_URL = "https://spotify23.p.rapidapi.com"
KEY = config["subscription_key"]
HEADERS = {
"X-RapidAPI-Key": KEY,
"X-RapidAPI-Host": "spotify23.p.rapidapi.com"
}

@tool.get("/spotify_search")
def spotify_search(query: str, query_type: str) -> dict:
"""
Search for songs & podcasts, artists, albums, playlists and more on Spotify.

:param query: Free-form spotify search query.
:param query_type: Type of the query, `albums`, `artists`, etc., best with `multi`.
:return: A dictionary with the response from the API.
"""

query_params = {
"q": query,
"type": query_type,
}

response = requests.get(BASE_URL + "/search/", headers=HEADERS, params=query_params)

return response.json()

return tool
5 changes: 5 additions & 0 deletions bmtools/tools/spotify/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Spotify

Contributor: [Chen Zhang](https://github.com/GeneZC)

You can get your RAIPID key here: https://rapidapi.com/hub
11 changes: 11 additions & 0 deletions bmtools/tools/spotify/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from bmtools.agent.singletool import load_single_tools, STQuestionAnswerer

tool_name, tool_url = 'Spotify', "http://127.0.0.1:8079/tools/spotify/"
tools_name, tools_config = load_single_tools(tool_name, tool_url)
print(tools_name, tools_config)

qa = STQuestionAnswerer()

agent = qa.load_tools(tools_name, tools_config)

agent("List famous songs of coldplay.")
1 change: 1 addition & 0 deletions host_local_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def load_rapidapi_tool():
server.load_tool("zillow", {"subscription_key": RAPIDAPI_KEY})
server.load_tool("airbnb", {"subscription_key": RAPIDAPI_KEY})
server.load_tool("job_search", {"subscription_key": RAPIDAPI_KEY})
server.load_tool("spotify", {"subscription_key": RAPIDAPI_KEY})

# def load_nllb_translation_tool():
# server.load_tool("nllb-translation")
Expand Down