mirror of
https://github.com/Mintplex-Labs/anything-llm.git
synced 2024-10-02 08:50:11 +02:00
Add chat-export to API (#831)
This commit is contained in:
parent
2974a969b5
commit
9e085baf5e
@ -1,5 +1,10 @@
|
|||||||
|
const { EventLogs } = require("../../../models/eventLogs");
|
||||||
const { SystemSettings } = require("../../../models/systemSettings");
|
const { SystemSettings } = require("../../../models/systemSettings");
|
||||||
const { getVectorDbClass } = require("../../../utils/helpers");
|
const { getVectorDbClass } = require("../../../utils/helpers");
|
||||||
|
const {
|
||||||
|
prepareWorkspaceChatsForExport,
|
||||||
|
exportChatsAsType,
|
||||||
|
} = require("../../../utils/helpers/chat/convertTo");
|
||||||
const { dumpENV, updateENV } = require("../../../utils/helpers/updateENV");
|
const { dumpENV, updateENV } = require("../../../utils/helpers/updateENV");
|
||||||
const { reqBody } = require("../../../utils/http");
|
const { reqBody } = require("../../../utils/http");
|
||||||
const { validApiKey } = require("../../../utils/middleware/validApiKey");
|
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 };
|
module.exports = { apiSystemEndpoints };
|
||||||
|
@ -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": {
|
"components": {
|
||||||
|
Loading…
Reference in New Issue
Block a user