mirror of
https://github.com/Mintplex-Labs/anything-llm.git
synced 2025-05-02 09:03:12 +00:00
Add optional limit and orderBy to dev api chat endpoint (#2559)
add optional limit and orderBy to dev api chat endpoint
This commit is contained in:
parent
ccde891aa2
commit
e719d05027
2 changed files with 46 additions and 3 deletions
server
|
@ -347,6 +347,18 @@ function apiWorkspaceEndpoints(app) {
|
|||
required: false,
|
||||
type: 'string'
|
||||
}
|
||||
#swagger.parameters['limit'] = {
|
||||
in: 'query',
|
||||
description: 'Optional number of chat messages to return (default: 100)',
|
||||
required: false,
|
||||
type: 'integer'
|
||||
}
|
||||
#swagger.parameters['orderBy'] = {
|
||||
in: 'query',
|
||||
description: 'Optional order of chat messages (asc or desc)',
|
||||
required: false,
|
||||
type: 'string'
|
||||
}
|
||||
#swagger.responses[200] = {
|
||||
content: {
|
||||
"application/json": {
|
||||
|
@ -378,7 +390,11 @@ function apiWorkspaceEndpoints(app) {
|
|||
*/
|
||||
try {
|
||||
const { slug } = request.params;
|
||||
const { apiSessionId = null } = request.query;
|
||||
const {
|
||||
apiSessionId = null,
|
||||
limit = 100,
|
||||
orderBy = "desc",
|
||||
} = request.query;
|
||||
const workspace = await Workspace.get({ slug });
|
||||
|
||||
if (!workspace) {
|
||||
|
@ -386,12 +402,21 @@ function apiWorkspaceEndpoints(app) {
|
|||
return;
|
||||
}
|
||||
|
||||
const validLimit = Math.max(1, parseInt(limit));
|
||||
const validOrderBy = ["asc", "desc"].includes(orderBy)
|
||||
? orderBy
|
||||
: "desc";
|
||||
|
||||
const history = apiSessionId
|
||||
? await WorkspaceChats.forWorkspaceByApiSessionId(
|
||||
workspace.id,
|
||||
apiSessionId
|
||||
apiSessionId,
|
||||
validLimit,
|
||||
{ createdAt: validOrderBy }
|
||||
)
|
||||
: await WorkspaceChats.forWorkspace(workspace.id);
|
||||
: await WorkspaceChats.forWorkspace(workspace.id, validLimit, {
|
||||
createdAt: validOrderBy,
|
||||
});
|
||||
response.status(200).json({ history: convertToChatHistory(history) });
|
||||
} catch (e) {
|
||||
console.error(e.message, e);
|
||||
|
|
|
@ -1660,6 +1660,24 @@
|
|||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "limit",
|
||||
"in": "query",
|
||||
"description": "Optional number of chat messages to return (default: 100)",
|
||||
"required": false,
|
||||
"schema": {
|
||||
"type": "integer"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "orderBy",
|
||||
"in": "query",
|
||||
"description": "Optional order of chat messages (asc or desc)",
|
||||
"required": false,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue