File size: 960 Bytes
f6091f7
916e00a
f6091f7
f616dbf
945f6e8
916e00a
 
 
1bb6e90
f6091f7
916e00a
 
 
945f6e8
916e00a
 
 
 
1bb6e90
916e00a
 
1bb6e90
9daa0fe
ff2cd25
916e00a
 
 
f616dbf
916e00a
f616dbf
29df9bc
916e00a
 
2016044
f616dbf
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
import { GoogleCustomSearch } from "openai-function-calling-tools";
import { LLMError, LLMStream } from './stream';

const handler = async (req, res) => {
  const { question } = await req.json();
  try {
    const googleCustomSearch = new GoogleCustomSearch({
        apiKey: process.env.API_KEY,
        googleCSEId: process.env.CONTEXT_KEY
    });
    const messages = [
        {
          role: "user",
          content: question
        },
      ];
    
    const functions = {
        googleCustomSearch
    };

    let promptToSend = "You are a helpful assistant";
    const stream = await LLMStream({ id: "gpt-3.5-turbo-0613" }, promptToSend, 0.8, messages, functions);
    return new Response(stream);
  } catch (error) {
    console.error(error);
    if (error instanceof LLMError) {
      res.status(500).send({ error: error.message });
    } else {
      res.status(500).send({ error: 'An error occurred' });
    }
  }
};

export default handler;