Spaces:
Running
Running
Clint Adams
commited on
Commit
·
efb9f2b
1
Parent(s):
c1b7205
refactor
Browse files- app.py +1 -36
- tools/boardgame_info.py +40 -0
app.py
CHANGED
@@ -1,10 +1,9 @@
|
|
1 |
from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel, LiteLLMModel, load_tool,tool
|
2 |
-
from pydantic import BaseModel
|
3 |
import datetime
|
4 |
-
import requests
|
5 |
import pytz
|
6 |
import yaml
|
7 |
from tools.final_answer import FinalAnswerTool
|
|
|
8 |
|
9 |
import os
|
10 |
import base64
|
@@ -31,40 +30,6 @@ trace_provider.add_span_processor(SimpleSpanProcessor(OTLPSpanExporter()))
|
|
31 |
|
32 |
SmolagentsInstrumentor().instrument(tracer_provider=trace_provider)
|
33 |
|
34 |
-
GAME_API_KEY = os.getenv("GAME_API_KEY")
|
35 |
-
GAME_API_BASE_URL = os.getenv("GAME_API_BASE_URL")
|
36 |
-
|
37 |
-
class Game_Response(BaseModel):
|
38 |
-
name: str
|
39 |
-
description: str
|
40 |
-
year_published: int
|
41 |
-
min_players: int
|
42 |
-
max_players: int
|
43 |
-
users_rated: int
|
44 |
-
average_rating: float
|
45 |
-
bayes_adjusted_average: float
|
46 |
-
complexity: float
|
47 |
-
|
48 |
-
@tool
|
49 |
-
def boardgame_lookup_tool(q:str)-> list[Game_Response]:
|
50 |
-
"""A tool that fetches information about board games
|
51 |
-
Args:
|
52 |
-
q: a search term representing part or all of a board game's name or description, prefixed with either "name:" or "description:"
|
53 |
-
"""
|
54 |
-
url = f'{GAME_API_BASE_URL}/games'
|
55 |
-
headers = {'x-api-key': f'{GAME_API_KEY}'}
|
56 |
-
response = requests.get(url, headers=headers, params={'q': q, 'search_type': search_type})
|
57 |
-
api_data_list = response.json()
|
58 |
-
return [Game_Response(name = api_data['name'],
|
59 |
-
description = api_data['description'],
|
60 |
-
year_published = api_data['year_published'],
|
61 |
-
min_players = api_data['min_players'],
|
62 |
-
max_players = api_data['max_players'],
|
63 |
-
users_rated = api_data['users_rated'],
|
64 |
-
average_rating = api_data['average'],
|
65 |
-
bayes_adjusted_average = api_data['bayes_average'],
|
66 |
-
complexity = api_data['weight']) for api_data in api_data_list]
|
67 |
-
|
68 |
@tool
|
69 |
def get_current_time_in_timezone(timezone: str) -> str:
|
70 |
"""A tool that fetches the current local time in a specified timezone.
|
|
|
1 |
from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel, LiteLLMModel, load_tool,tool
|
|
|
2 |
import datetime
|
|
|
3 |
import pytz
|
4 |
import yaml
|
5 |
from tools.final_answer import FinalAnswerTool
|
6 |
+
from tools.boardgame_info import boardgame_lookup_tool
|
7 |
|
8 |
import os
|
9 |
import base64
|
|
|
30 |
|
31 |
SmolagentsInstrumentor().instrument(tracer_provider=trace_provider)
|
32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
@tool
|
34 |
def get_current_time_in_timezone(timezone: str) -> str:
|
35 |
"""A tool that fetches the current local time in a specified timezone.
|
tools/boardgame_info.py
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import requests
|
3 |
+
|
4 |
+
from typing import Any, Optional
|
5 |
+
from pydantic import BaseModel
|
6 |
+
from smolagents.tools import tool
|
7 |
+
|
8 |
+
GAME_API_KEY = os.getenv("GAME_API_KEY")
|
9 |
+
GAME_API_BASE_URL = os.getenv("GAME_API_BASE_URL")
|
10 |
+
|
11 |
+
class Game_Response(BaseModel):
|
12 |
+
name: str
|
13 |
+
description: str
|
14 |
+
year_published: int
|
15 |
+
min_players: int
|
16 |
+
max_players: int
|
17 |
+
users_rated: int
|
18 |
+
average_rating: float
|
19 |
+
bayes_adjusted_average_rating: float
|
20 |
+
complexity: float
|
21 |
+
|
22 |
+
@tool
|
23 |
+
def boardgame_lookup_tool(q:str)-> list[Game_Response]:
|
24 |
+
"""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).
|
25 |
+
Args:
|
26 |
+
q: a search term representing part or all of a board game's name or description, prefixed with either "name:" or "description:"
|
27 |
+
"""
|
28 |
+
url = f'{GAME_API_BASE_URL}/games'
|
29 |
+
headers = {'x-api-key': f'{GAME_API_KEY}'}
|
30 |
+
response = requests.get(url, headers=headers, params={'q': q})
|
31 |
+
api_data_list = response.json()
|
32 |
+
return [Game_Response(name = api_data['name'],
|
33 |
+
description = api_data['description'],
|
34 |
+
year_published = api_data['year_published'],
|
35 |
+
min_players = api_data['min_players'],
|
36 |
+
max_players = api_data['max_players'],
|
37 |
+
users_rated = api_data['users_rated'],
|
38 |
+
average_rating = api_data['average'],
|
39 |
+
bayes_adjusted_average_rating = api_data['bayes_average'],
|
40 |
+
complexity = api_data['weight']) for api_data in api_data_list]
|