File size: 1,630 Bytes
efb9f2b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
import requests

from typing import Any, Optional
from pydantic import BaseModel
from smolagents.tools import tool

GAME_API_KEY = os.getenv("GAME_API_KEY")
GAME_API_BASE_URL = os.getenv("GAME_API_BASE_URL")

class Game_Response(BaseModel):
    name: str
    description: str
    year_published: int
    min_players: int
    max_players: int
    users_rated: int
    average_rating: float
    bayes_adjusted_average_rating: float
    complexity: float

@tool
def boardgame_lookup_tool(q:str)-> list[Game_Response]:
    """A tool that fetches information about board games and returns ratings (on a scale up to 10) and weights or complexities (on a scale up to 5).
    Args:
        q: a search term representing part or all of a board game's name or description, prefixed with either "name:" or "description:"
    """
    url = f'{GAME_API_BASE_URL}/games'
    headers = {'x-api-key': f'{GAME_API_KEY}'}
    response = requests.get(url, headers=headers, params={'q': q})
    api_data_list = response.json()
    return [Game_Response(name = api_data['name'],
                         description = api_data['description'],
                         year_published = api_data['year_published'],
                         min_players = api_data['min_players'],
                         max_players = api_data['max_players'],
                         users_rated = api_data['users_rated'],
                         average_rating = api_data['average'],
                         bayes_adjusted_average_rating = api_data['bayes_average'],
                         complexity = api_data['weight']) for api_data in api_data_list]