matt HOFFNER commited on
Commit
3db52d6
β€’
1 Parent(s): 3bbf649

nba api works

Browse files
Files changed (1) hide show
  1. 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
- const response = await getJson({
15
- engine: "google",
16
- api_key: apiKey,
17
- q: input,
18
- location: "Seattle, Washington",
19
- });
20
-
21
- return JSON.stringify(response['sports_results']);
 
 
 
 
 
 
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 };