matt HOFFNER
update names
33ee259
raw
history blame
1.03 kB
import { Tool } from 'openai-function-calling-tools';
import { z } from 'zod';
import { getJson } from 'serpapi';
function createSportsResultsApi({ apiKey }: { apiKey: string }) {
const paramsSchema = z.object({
input: z.string(),
});
const name = 'sports_results';
const description = 'A custom search engine for sports scores and results. Useful for when you need to answer questions about current sports scores (like nba or nfl). Input should be a search query. Outputs a JSON array of results.';
const execute = async ({ input }: z.infer<typeof paramsSchema>) => {
try {
const response = await getJson({
engine: "google",
api_key: apiKey,
q: input,
location: "Seattle, Washington",
});
return JSON.stringify(response['sports_results']);
} catch (error) {
throw new Error(`Error in serpApi: ${error}`);
}
};
return new Tool(paramsSchema, name, description, execute).tool;
}
export { createSportsResultsApi };