matt HOFFNER
commited on
Commit
β’
3db52d6
1
Parent(s):
3bbf649
nba api works
Browse files- app/tools/scores.ts +16 -10
app/tools/scores.ts
CHANGED
@@ -11,20 +11,26 @@ function createSportsResultsApi({ apiKey }: { apiKey: string }) {
|
|
11 |
|
12 |
const execute = async ({ input }: z.infer<typeof paramsSchema>) => {
|
13 |
try {
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
} catch (error) {
|
23 |
-
throw new Error(`Error in serpApi: ${error}`);
|
24 |
}
|
25 |
};
|
26 |
|
27 |
return new Tool(paramsSchema, name, description, execute).tool;
|
28 |
}
|
29 |
|
30 |
-
export { createSportsResultsApi };
|
|
|
11 |
|
12 |
const execute = async ({ input }: z.infer<typeof paramsSchema>) => {
|
13 |
try {
|
14 |
+
if (input.toLowerCase().includes('nba')) {
|
15 |
+
const results = await fetch("https://data.nba.com/data/10s/v2015/json/mobile_teams/nba/2023/scores/00_todays_scores.json");
|
16 |
+
const games = await results.json();
|
17 |
+
return JSON.stringify(games.gs.g);
|
18 |
+
} else {
|
19 |
+
const response = await getJson({
|
20 |
+
engine: "google",
|
21 |
+
api_key: apiKey,
|
22 |
+
q: input,
|
23 |
+
location: "Seattle, Washington",
|
24 |
+
});
|
25 |
+
|
26 |
+
return JSON.stringify(response['sports_results']);
|
27 |
+
}
|
28 |
} catch (error) {
|
29 |
+
throw new Error(`Error in serpApi or NBA API: ${error}`);
|
30 |
}
|
31 |
};
|
32 |
|
33 |
return new Tool(paramsSchema, name, description, execute).tool;
|
34 |
}
|
35 |
|
36 |
+
export { createSportsResultsApi };
|