Skip to content

Commit

Permalink
feat: Add batch files uploading endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
zAlweNy26 committed Jul 18, 2024
1 parent 4d2b0bd commit e5f6074
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/routes/rabbit_hole.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,45 @@ export function fileIngestion(app: App) {
400: 'error',
},
})
.post('/files', async ({ rh, body, query, stray, log, HttpError }) => {
const { files } = body, { sync, chunkOverlap, chunkSize } = query
try {
if (sync) {
for (const file of files)
await rh.ingestFile(stray, file, chunkSize, chunkOverlap)
}
else {
for (const file of files)
rh.ingestFile(stray, file, chunkSize, chunkOverlap).catch(log.error)
}
}
catch (error) {
log.error('Error while ingesting files:', error)
throw HttpError.InternalServer('Error while ingesting the passed files')
}
return {
info: sync ? 'Files have been ingested successfully.' : 'Files are being ingested asynchronously...',
}
}, {
body: t.Object({
files: t.Files(),
}),
query: t.Object({
sync: t.BooleanString({ default: true }),
chunkSize: t.Numeric({ default: 256 }),
chunkOverlap: t.Numeric({ default: 64 }),
}),
detail: {
description: 'Upload a list of files whose contents will be extracted and segmented into chunks. Chunks will be then vectorized and stored into documents memory.',
summary: 'Upload files',
},
response: {
200: t.Object({
info: t.String(),
}),
400: 'error',
},
})
.post('/memory', async ({ rh, body, query, log, HttpError }) => {
const { file } = body, { sync } = query
try {
Expand Down

0 comments on commit e5f6074

Please sign in to comment.