File size: 1,712 Bytes
8426b1e
a73e8b4
607207a
a73e8b4
 
 
 
 
 
 
 
 
 
607207a
 
a73e8b4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8426b1e
5b87497
1f55d89
607207a
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
42
43
44
45
46
47
48
49
50
import { createSearchApi } from '../../../app/tools/search';
import { createOddsApi } from '@/app/tools/odds';
import { createSportsResultsApi } from '@/app/tools/scores';
import { handleContentText } from './utils';
import { similaritySearch } from './vector-store';

const urlRegex = /(https?:\/\/[^\s]+)/g;

const [serpApi] =
  createSearchApi({
    apiKey: process.env.SERP_API_KEY || "",
});

const [sportsScoresApi] = createSportsResultsApi({ apiKey: process.env.SERP_API_KEY || "",});

const [oddsApi] = createOddsApi({ apiKey: process.env.ODDS_API_KEY || "" });
type FunctionOutput = any;
type FunctionInput = any;

export const odds: FunctionOutput = async ({ input }: FunctionInput) => {
  const content = await oddsApi({input});
  const oddsApiResults = await similaritySearch(input, content);
  return oddsApiResults;
}

export const surfer: FunctionOutput = async ({ input }: FunctionInput) => {
  const urls = input.match(urlRegex);
  const targetUrl = urls ? urls[0] : null;
  const promptWithoutUrl = urls ? input.replace(urlRegex, '').trim() : input;

  const content: string = await handleContentText(targetUrl)
  if (!content) {
    return `Couldn't find ${targetUrl}, here is the prompt: ${promptWithoutUrl}`;
  }

  const surferApiResults = await similaritySearch(promptWithoutUrl, content);
  return surferApiResults;
}

export const serp: FunctionOutput = async ({ input }: FunctionInput) => {
  const content: string = await serpApi({input})
  const serpApiResults = await similaritySearch(input, content);
  return serpApiResults;
}

export const sports: FunctionOutput = async ({ input }: FunctionInput) => {
  const content: string = await sportsScoresApi({input})
  return content;
}