-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathsuno_ai_tool.py
45 lines (38 loc) · 1.35 KB
/
suno_ai_tool.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import time
import json
import requests
from typing import Type
from pydantic.v1 import BaseModel, Field
from crewai_tools import BaseTool
class SunoToolSchema(BaseModel):
"""Input for SunoTool"""
url: str = Field(..., description="URL for the Suno API. This field is mandatory")
genre: str = Field(..., description="The song genre. E.g. Hip Hop, Rap, Pop, etc.")
class SunoTool(BaseTool):
name: str = "Generate a song from the lyrics"
description: str = "A tool that can be used to generate a song from the provided lyrics."
args_schema: Type[BaseModel] = SunoToolSchema
url: str = ""
genre: str = ""
def __init__(self, url: str, genre: str, **kwargs):
super().__init__(**kwargs)
self.url = f"{url}/api/custom_generate"
self.genre = genre
def _run(
self,
lyrics: str,
**kwargs
):
payload = {
"prompt": lyrics,
"tags": self.genre,
"title": "Melody Agents Song",
"make_instrumental": False,
"wait_audio": False
}
try:
response = requests.post(self.url, json=payload, headers={'Content-Type': 'application/json'})
_ = response.json()
except Exception as e:
raise ValueError(e)
return "Your songs are being generated ... 🤖"