Merge branch 'master' of github.com:Mintplex-Labs/anything-llm

This commit is contained in:
timothycarambat 2024-02-28 12:05:57 -08:00
commit 60fc5f715a
2 changed files with 125 additions and 0 deletions

View File

@ -1,5 +1,10 @@
const { EventLogs } = require("../../../models/eventLogs");
const { SystemSettings } = require("../../../models/systemSettings");
const { getVectorDbClass } = require("../../../utils/helpers");
const {
prepareWorkspaceChatsForExport,
exportChatsAsType,
} = require("../../../utils/helpers/chat/convertTo");
const { dumpENV, updateENV } = require("../../../utils/helpers/updateENV");
const { reqBody } = require("../../../utils/http");
const { validApiKey } = require("../../../utils/middleware/validApiKey");
@ -147,6 +152,60 @@ function apiSystemEndpoints(app) {
}
}
);
app.get(
"/v1/system/export-chats",
[validApiKey],
async (request, response) => {
/*
#swagger.tags = ['System Settings']
#swagger.description = 'Export all of the chats from the system in a known format. Output depends on the type sent. Will be send with the correct header for the output.'
#swagger.parameters['type'] = {
in: 'query',
description: "Export format jsonl, json, csv, jsonAlpaca",
required: false,
type: 'string'
}
#swagger.responses[200] = {
content: {
"application/json": {
schema: {
type: 'object',
example: [
{
"role": "user",
"content": "What is AnythinglLM?"
},
{
"role": "assistant",
"content": "AnythingLLM is a knowledge graph and vector database management system built using NodeJS express server. It provides an interface for handling all interactions, including vectorDB management and LLM (Language Model) interactions."
},
]
}
}
}
}
#swagger.responses[403] = {
schema: {
"$ref": "#/definitions/InvalidAPIKey"
}
}
*/
try {
const { type = "jsonl" } = request.query;
const chats = await prepareWorkspaceChatsForExport(type);
const { contentType, data } = await exportChatsAsType(chats, type);
await EventLogs.logEvent("exported_chats", {
type,
});
response.setHeader("Content-Type", contentType);
response.status(200).send(data);
} catch (e) {
console.log(e.message, e);
response.sendStatus(500).end();
}
}
);
}
module.exports = { apiSystemEndpoints };

View File

@ -2232,6 +2232,72 @@
}
}
}
},
"/v1/system/export-chats": {
"get": {
"tags": [
"System Settings"
],
"description": "Export all of the chats from the system in a known format. Output depends on the type sent. Will be send with the correct header for the output.",
"parameters": [
{
"name": "Authorization",
"in": "header",
"schema": {
"type": "string"
}
},
{
"name": "type",
"in": "query",
"description": "Export format jsonl, json, csv, jsonAlpaca",
"required": false,
"schema": {
"type": "string"
}
}
],
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"type": "object",
"example": [
{
"role": "user",
"content": "What is AnythinglLM?"
},
{
"role": "assistant",
"content": "AnythingLLM is a knowledge graph and vector database management system built using NodeJS express server. It provides an interface for handling all interactions, including vectorDB management and LLM (Language Model) interactions."
}
]
}
}
}
},
"403": {
"description": "Forbidden",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/InvalidAPIKey"
}
},
"application/xml": {
"schema": {
"$ref": "#/components/schemas/InvalidAPIKey"
}
}
}
},
"500": {
"description": "Internal Server Error"
}
}
}
}
},
"components": {