matt HOFFNER
fix
f7857c1
raw
history blame
997 Bytes
import { GoogleCustomSearch } from "openai-function-calling-tools";
import { LLMError, LLMStream } from './stream';
const handler = async (req, res) => {
try {
const googleCustomSearch = new GoogleCustomSearch({
apiKey: process.env.API_KEY,
googleCSEId: process.env.CONTEXT_KEY
});
const messages = [
{
role: "user",
content: req.body.question
},
];
const functions = {
googleCustomSearch
};
let promptToSend = "You are a helpful assistant";
console.log(messages, promptToSend);
const stream = await LLMStream({ id: "gpt-3.5-turbo-0613" }, promptToSend, 0.8, messages, functions);
console.log(stream);
res.status(200).send(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;