import requests class RandomCharacterTool: name = "random_character" description = "This tool fetches a random character from the 'https://randomuser.me/api/' open API." outputs = ["character"] def __call__(self): API_URL = "https://randomuser.me/api/" response = requests.get(API_URL) data = response.json()['results'][0] # Extract the relevant character information character = { "gender": data['gender'], "name": { "title": data['name']['title'], "first": data['name']['first'], "last": data['name']['last'] }, "location": { "street": { "number": data['location']['street']['number'], "name": data['location']['street']['name'] }, "city": data['location']['city'], "state": data['location']['state'], "country": data['location']['country'], "postcode": data['location']['postcode'], "coordinates": { "latitude": data['location']['coordinates']['latitude'], "longitude": data['location']['coordinates']['longitude'] }, "timezone": { "offset": data['location']['timezone']['offset'], "description": data['location']['timezone']['description'] } }, "email": data['email'], "login": { "uuid": data['login']['uuid'], "username": data['login']['username'], "password": data['login']['password'], "salt": data['login']['salt'], "md5": data['login']['md5'], "sha1": data['login']['sha1'], "sha256": data['login']['sha256'] }, "dob": { "date": data['dob']['date'], "age": data['dob']['age'] }, "registered": { "date": data['registered']['date'], "age": data['registered']['age'] }, "phone": data['phone'], "cell": data['cell'], "id": { "name": data['id']['name'], "value": data['id']['value'] }, "picture": { "large": data['picture']['large'], "medium": data['picture']['medium'], "thumbnail": data['picture']['thumbnail'] }, "nat": data['nat'] } return {"character": character}