Skip to content

Commit

Permalink
docs: improve openapi documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
zAlweNy26 committed Oct 18, 2024
1 parent ad774e3 commit d7d6169
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/routes/embedder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,6 @@ export const embedderRoutes = new Elysia({
200: 'customSetting',
400: 'error',
404: 'error',
500: 'error',
},
})
1 change: 1 addition & 0 deletions src/routes/llm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,6 @@ export const llmRoutes = new Elysia({
200: 'customSetting',
400: 'error',
404: 'error',
500: 'error',
},
})
21 changes: 19 additions & 2 deletions src/routes/memory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export const memoryRoutes = new Elysia({
}),
response: {
200: 'memoryRecall',
400: 'error',
500: 'error',
},
}).get('/collections', async () => {
Expand Down Expand Up @@ -97,6 +98,7 @@ export const memoryRoutes = new Elysia({
],
}],
}),
400: 'error',
500: 'error',
},
}).delete('/collections', async ({ mh, log, HttpError, set }) => {
Expand All @@ -118,6 +120,7 @@ export const memoryRoutes = new Elysia({
},
response: {
204: t.Void({ title: 'Collections wiped', description: 'Collections wiped successfully' }),
400: 'error',
500: 'error',
},
}).delete('/collections/:collectionId', async ({ mh, params, log, HttpError, set }) => {
Expand All @@ -144,6 +147,7 @@ export const memoryRoutes = new Elysia({
}),
response: {
204: t.Void({ title: 'Collection wiped', description: 'Collection wiped successfully' }),
400: 'error',
404: 'error',
500: 'error',
},
Expand Down Expand Up @@ -222,6 +226,7 @@ export const memoryRoutes = new Elysia({
],
}],
}),
400: 'error',
404: 'error',
500: 'error',
},
Expand Down Expand Up @@ -256,14 +261,15 @@ export const memoryRoutes = new Elysia({
}),
response: {
204: t.Void({ title: 'Documents wiped', description: 'Documents wiped successfully' }),
400: 'error',
404: 'error',
500: 'error',
},
}).delete('/collections/:collectionId/point/:pointId', async ({ params, log, HttpError, set }) => {
const { collectionId, pointId } = params
const collections = Object.keys(cat.vectorMemory.collections)
if (!collections.includes(collectionId)) throw HttpError.NotFound('Collection not found.')
try {
const collections = Object.keys(cat.vectorMemory.collections)
if (!collections.includes(collectionId)) throw HttpError.NotFound('Collection not found.')
const points = await cat.vectorMemory.db.retrieve(collectionId, { ids: [pointId] })
if (points.length === 0) throw HttpError.NotFound('Point not found.')
await cat.vectorMemory.collections[collectionId]?.deletePoints([pointId])
Expand All @@ -284,11 +290,14 @@ export const memoryRoutes = new Elysia({
}),
response: {
204: t.Void({ title: 'Point wiped', description: 'Point wiped successfully' }),
400: 'error',
404: 'error',
500: 'error',
},
}).get('/collections/:collectionId/point/:pointId', async ({ params, log, HttpError }) => {
const { collectionId, pointId } = params
const collections = Object.keys(cat.vectorMemory.collections)
if (!collections.includes(collectionId)) throw HttpError.NotFound('Collection not found.')
try {
const points = await cat.vectorMemory.collections[collectionId]!.getPoints([pointId])
if (points.length === 0) throw HttpError.NotFound('Point not found.')
Expand Down Expand Up @@ -327,11 +336,14 @@ export const memoryRoutes = new Elysia({
},
}],
}),
400: 'error',
404: 'error',
500: 'error',
},
}).post('/collections/:collectionId/point', async ({ params, body, log, HttpError }) => {
const { collectionId } = params, { content, payload, vector } = body
const collections = Object.keys(cat.vectorMemory.collections)
if (!collections.includes(collectionId)) throw HttpError.NotFound('Collection not found.')
try {
const point = await cat.vectorMemory.collections[collectionId]!.addPoint(content, vector, payload)
if (!point) throw new Error('Error adding point.')
Expand Down Expand Up @@ -376,6 +388,8 @@ export const memoryRoutes = new Elysia({
id: '1da746f8-a832-4a45-a120-4549e17a1df7',
}],
}),
400: 'error',
404: 'error',
500: 'error',
},
}).get('/history', ({ stray }) => {
Expand All @@ -389,6 +403,7 @@ export const memoryRoutes = new Elysia({
},
response: {
200: 'chatHistory',
400: 'error',
},
}).delete('/history', ({ stray, set }) => {
stray.clearHistory()
Expand All @@ -400,6 +415,7 @@ export const memoryRoutes = new Elysia({
},
response: {
204: t.Void({ title: 'History wiped', description: 'History wiped successfully' }),
400: 'error',
},
}).put('/history', ({ stray, body, set }) => {
stray.addHistory(body.history)
Expand Down Expand Up @@ -427,5 +443,6 @@ export const memoryRoutes = new Elysia({
}),
response: {
204: t.Void({ title: 'History added', description: 'History added successfully' }),
400: 'error',
},
})
22 changes: 18 additions & 4 deletions src/routes/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const pluginsRoutes = new Elysia({
},
response: {
200: 'pluginsInfo',
400: 'error',
},
}).get('/:pluginId', ({ mh, params, HttpError }) => {
const id = params.pluginId
Expand All @@ -36,6 +37,7 @@ export const pluginsRoutes = new Elysia({
params: t.Object({ pluginId: t.String({ title: 'Plugin ID', description: 'ID of the plugin whose information will be retrieved' }) }),
response: {
200: 'pluginInfo',
400: 'error',
404: 'error',
},
}).delete('/:pluginId', async ({ mh, params, log, HttpError, set }) => {
Expand All @@ -59,8 +61,9 @@ export const pluginsRoutes = new Elysia({
params: t.Object({ pluginId: t.String({ title: 'Plugin ID', description: 'ID of the plugin to delete' }) }),
response: {
204: t.Void({ title: 'Plugin removed', description: 'The plugin has been removed' }),
404: 'error',
400: 'error',
404: 'error',
500: 'error',
},
}).post('/upload', async ({ body, log, mh, HttpError }) => {
const { file } = body
Expand Down Expand Up @@ -88,6 +91,7 @@ export const pluginsRoutes = new Elysia({
}
catch (error) {
log.warn(error)
throw HttpError.InternalServer('Failed to install plugin')
}

return {
Expand Down Expand Up @@ -150,18 +154,22 @@ export const pluginsRoutes = new Elysia({
body: t.Object({ active: t.Boolean({ default: true }) }, { title: 'Plugin status', description: 'Status of the plugin' }),
response: {
200: t.Object({ active: t.Boolean() }, { title: 'Plugin status', description: 'Plugin toggled successfully' }),
404: 'error',
400: 'error',
404: 'error',
500: 'error',
},
}).patch('/toggle/:pluginId/procedure/:procedureName', async ({ params, body, mh, db, HttpError }) => {
const { pluginId, procedureName } = params, { active } = body
const p = mh.getPlugin(pluginId)
if (!p) throw HttpError.NotFound('Plugin not found')

const tool = p.tools.find(t => t.name === procedureName)
const form = p.forms.find(f => f.name === procedureName)
if (!tool && !form) throw HttpError.NotFound('Procedure not found')

if (tool) tool.active = active
if (form) form.active = active

db.update((db) => {
if (tool) {
if (tool.active) db.activeTools.push(procedureName)
Expand All @@ -172,6 +180,7 @@ export const pluginsRoutes = new Elysia({
else db.activeForms = db.activeForms.filter(f => f !== procedureName)
}
})

return {
active: (tool?.active ?? form?.active) ?? false,
}
Expand All @@ -190,8 +199,8 @@ export const pluginsRoutes = new Elysia({
body: t.Object({ active: t.Boolean({ default: true }) }, { title: 'Procedure status', description: 'Status of the procedure' }),
response: {
200: t.Object({ active: t.Boolean() }, { title: 'Procedure activation status', description: 'Procedure toggled successfully' }),
404: 'error',
400: 'error',
404: 'error',
},
}).get('/settings', ({ mh }) => {
const ps = mh.installedPlugins.map(p => ({
Expand All @@ -209,11 +218,13 @@ export const pluginsRoutes = new Elysia({
},
response: {
200: 'pluginsSettings',
400: 'error',
},
}).get('/settings/:pluginId', ({ mh, params, HttpError }) => {
const id = params.pluginId
const p = mh.getPlugin(id)
if (!p) throw HttpError.NotFound('Plugin not found')

return {
name: id,
schema: zodToJsonSchema(p.schema),
Expand All @@ -227,15 +238,18 @@ export const pluginsRoutes = new Elysia({
params: t.Object({ pluginId: t.String({ title: 'Plugin ID', description: 'ID of the plugin whose settings will be retrieved' }) }),
response: {
200: 'pluginSettings',
400: 'error',
404: 'error',
},
}).put('/settings/:pluginId', ({ body, params, mh, HttpError }) => {
const id = params.pluginId
const p = mh.getPlugin(id)
if (!p) throw HttpError.NotFound('Plugin not found')

const parsed = p.schema.safeParse(body)
if (!parsed.success) throw HttpError.InternalServer(parsed.error.errors.map(e => e.message).join())
p.settings = parsed.data

return {
name: id,
value: parsed.data,
Expand All @@ -255,7 +269,7 @@ export const pluginsRoutes = new Elysia({
}),
response: {
200: 'customSetting',
404: 'error',
400: 'error',
404: 'error',
},
})
6 changes: 6 additions & 0 deletions src/routes/rabbit_hole.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const rabbitHoleRoutes = new Elysia({
allowedMimetypes: ['text/plain', 'application/pdf', 'application/json'],
}],
}),
400: 'error',
},
}).post('/chunk', async ({ rh, body, query, stray, log, HttpError }) => {
const { sync, source } = query, { chunk, metadata } = body
Expand Down Expand Up @@ -59,6 +60,7 @@ export const rabbitHoleRoutes = new Elysia({
description: 'Chunk ingested successfully',
}),
400: 'error',
500: 'error',
},
}).post('/file', async ({ rh, body, query, stray, log, HttpError }) => {
const { file, metadata } = body, { sync, chunkOverlap, chunkSize } = query
Expand Down Expand Up @@ -95,6 +97,7 @@ export const rabbitHoleRoutes = new Elysia({
description: 'File ingested successfully',
}),
400: 'error',
500: 'error',
},
}).post('/files', async ({ rh, body, query, stray, log, HttpError }) => {
const { content } = body, { sync, chunkOverlap, chunkSize } = query
Expand Down Expand Up @@ -139,6 +142,7 @@ export const rabbitHoleRoutes = new Elysia({
description: 'Files ingested successfully',
}),
400: 'error',
500: 'error',
},
}).post('/web', async ({ rh, body, query, stray, log, HttpError }) => {
const { webUrl, metadata } = body, { sync, chunkOverlap, chunkSize } = query
Expand Down Expand Up @@ -179,6 +183,7 @@ export const rabbitHoleRoutes = new Elysia({
description: 'URL ingested successfully',
}),
400: 'error',
500: 'error',
},
}).post('/memory', async ({ rh, body, query, log, HttpError }) => {
const { file } = body, { sync } = query
Expand Down Expand Up @@ -212,5 +217,6 @@ export const rabbitHoleRoutes = new Elysia({
description: 'Memory ingested successfully',
}),
400: 'error',
500: 'error',
},
})
2 changes: 2 additions & 0 deletions src/routes/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const settingsRoutes = new Elysia({
response: {
200: 'generic',
400: 'error',
404: 'error',
},
}).put('/:settingId', ({ db, params, body, HttpError }) => {
const id = params.settingId
Expand All @@ -53,6 +54,7 @@ export const settingsRoutes = new Elysia({
200: 'generic',
400: 'error',
404: 'error',
500: 'error',
},
}).post('/:settingId', ({ db, params, body, HttpError }) => {
const id = params.settingId
Expand Down

0 comments on commit d7d6169

Please sign in to comment.