matt HOFFNER commited on
Commit
caaca78
β€’
1 Parent(s): e3c92ea
app/api/chat/route.ts CHANGED
@@ -1,10 +1,10 @@
1
  import { Configuration, OpenAIApi } from "openai-edge";
2
  import { OpenAIStream, StreamingTextResponse } from "ai";
3
  import { createUrlSurfer } from "@/app/tools/surfer";
4
- import { createSerpApi } from "@/app/tools/serp-api";
5
 
6
  const [, urlSurferSchema] = createUrlSurfer();
7
- const [, serpApiSchema] = createSerpApi({ apiKey: process.env.SERP_API_KEY || '' });
8
 
9
  const config = new Configuration({
10
  apiKey: process.env.OPENAI_API_KEY,
 
1
  import { Configuration, OpenAIApi } from "openai-edge";
2
  import { OpenAIStream, StreamingTextResponse } from "ai";
3
  import { createUrlSurfer } from "@/app/tools/surfer";
4
+ import { createSearchApi } from "@/app/tools/search";
5
 
6
  const [, urlSurferSchema] = createUrlSurfer();
7
+ const [, serpApiSchema] = createSearchApi({ apiKey: process.env.SERP_API_KEY || '' });
8
 
9
  const config = new Configuration({
10
  apiKey: process.env.OPENAI_API_KEY,
app/page.tsx CHANGED
@@ -22,7 +22,7 @@ const Page: React.FC = () => {
22
  "Content-Type": "application/json",
23
  },
24
  body: JSON.stringify({
25
- prompt: input,
26
  name: name
27
  })
28
  } as any);
 
22
  "Content-Type": "application/json",
23
  },
24
  body: JSON.stringify({
25
+ prompt: args,
26
  name: name
27
  })
28
  } as any);
app/tools/{serp-api.ts β†’ search.ts} RENAMED
@@ -2,11 +2,11 @@ import { Tool } from 'openai-function-calling-tools';
2
  import { z } from 'zod';
3
  import { getJson } from 'serpapi';
4
 
5
- function createSerpApi({ apiKey }: { apiKey: string }) {
6
  const paramsSchema = z.object({
7
  input: z.string(),
8
  });
9
- const name = 'serpApi';
10
  const description = 'A custom search engine. Useful for when you need to answer questions about current events. Input should be a search query. Outputs a JSON array of results.';
11
 
12
  const execute = async ({ input }: z.infer<typeof paramsSchema>) => {
@@ -17,8 +17,7 @@ function createSerpApi({ apiKey }: { apiKey: string }) {
17
  q: input,
18
  location: "Seattle, Washington",
19
  });
20
-
21
- console.log(response);
22
  return JSON.stringify(response);
23
  } catch (error) {
24
  throw new Error(`Error in serpApi: ${error}`);
@@ -28,4 +27,4 @@ function createSerpApi({ apiKey }: { apiKey: string }) {
28
  return new Tool(paramsSchema, name, description, execute).tool;
29
  }
30
 
31
- export { createSerpApi };
 
2
  import { z } from 'zod';
3
  import { getJson } from 'serpapi';
4
 
5
+ function createSearchApi({ apiKey }: { apiKey: string }) {
6
  const paramsSchema = z.object({
7
  input: z.string(),
8
  });
9
+ const name = 'Search API';
10
  const description = 'A custom search engine. Useful for when you need to answer questions about current events. Input should be a search query. Outputs a JSON array of results.';
11
 
12
  const execute = async ({ input }: z.infer<typeof paramsSchema>) => {
 
17
  q: input,
18
  location: "Seattle, Washington",
19
  });
20
+
 
21
  return JSON.stringify(response);
22
  } catch (error) {
23
  throw new Error(`Error in serpApi: ${error}`);
 
27
  return new Tool(paramsSchema, name, description, execute).tool;
28
  }
29
 
30
+ export { createSearchApi };
app/tools/surfer.ts CHANGED
@@ -5,7 +5,7 @@ function createUrlSurfer() {
5
  const paramsSchema = z.object({
6
  input: z.string(),
7
  });
8
- const name = 'surfer';
9
  const description = 'A custom URL navigator. Useful when a URL is provided with a question. Input should be a prompt with a URL. Outputs a JSON array of relevant results.';
10
 
11
  return new Tool(paramsSchema, name, description, {} as any).tool;
 
5
  const paramsSchema = z.object({
6
  input: z.string(),
7
  });
8
+ const name = 'URL Surfer';
9
  const description = 'A custom URL navigator. Useful when a URL is provided with a question. Input should be a prompt with a URL. Outputs a JSON array of relevant results.';
10
 
11
  return new Tool(paramsSchema, name, description, {} as any).tool;
pages/api/functions/index.ts CHANGED
@@ -7,7 +7,7 @@ import puppeteer from 'puppeteer';
7
  import { RecursiveCharacterTextSplitter } from 'langchain/text_splitter';
8
  import { MemoryVectorStore } from 'langchain/vectorstores/memory';
9
  import { HuggingFaceTransformersEmbeddings } from "langchain/embeddings/hf_transformers";
10
- import { createSerpApi } from '../../../app/tools/serp-api'
11
 
12
  export const config = {
13
  api: {
 
7
  import { RecursiveCharacterTextSplitter } from 'langchain/text_splitter';
8
  import { MemoryVectorStore } from 'langchain/vectorstores/memory';
9
  import { HuggingFaceTransformersEmbeddings } from "langchain/embeddings/hf_transformers";
10
+ import { createSerpApi } from '../../../app/tools/search'
11
 
12
  export const config = {
13
  api: {