MCPcopy
hub / github.com/guangzhengli/ChatFiles / handler

Function handler

pages/api/embedding.ts:10–28  ·  view source on GitHub ↗
(req: NextApiRequest, res: NextApiResponse)

Source from the content-addressed store, hash-verified

8const folderPath = NEXT_PUBLIC_CHAT_FILES_UPLOAD_PATH;
9
10const handler = async (req: NextApiRequest, res: NextApiResponse) => {
11 console.log("beginning embedding handler");
12 const keyConfiguration = getKeyConfiguration(req);
13
14 const { fileName, fileType } = req.body;
15 const loader = getDocumentLoader(fileType, `${folderPath}/${fileName}.${fileType}`);
16 const document = await loader.load();
17 const splitDocuments = await getSplitterDocument(keyConfiguration, document);
18 splitDocuments.map((doc) => {
19 doc.metadata = { file_name : fileName };
20 });
21 try {
22 await saveEmbeddings(keyConfiguration, splitDocuments);
23 res.status(200).json({ message: 'save supabase embedding successes' });
24 } catch (e) {
25 console.error(e);
26 res.status(500).json({ message: (e as Error).message });
27 }
28}
29
30export default handler;

Callers

nothing calls this directly

Calls 4

getKeyConfigurationFunction · 0.90
getDocumentLoaderFunction · 0.90
getSplitterDocumentFunction · 0.90
saveEmbeddingsFunction · 0.90

Tested by

no test coverage detected