Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Anything Llm
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mirrored_repos
MachineLearning
Mintplex Labs
Anything Llm
Commits
3f5b4196
Unverified
Commit
3f5b4196
authored
1 year ago
by
Timothy Carambat
Committed by
GitHub
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Add support for chatting via the API (#261)
parent
62d39eb4
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
server/endpoints/api/workspace/index.js
+76
-1
76 additions, 1 deletion
server/endpoints/api/workspace/index.js
server/swagger/openapi.json
+84
-0
84 additions, 0 deletions
server/swagger/openapi.json
with
160 additions
and
1 deletion
server/endpoints/api/workspace/index.js
+
76
−
1
View file @
3f5b4196
...
...
@@ -3,7 +3,10 @@ const { Telemetry } = require("../../../models/telemetry");
const
{
DocumentVectors
}
=
require
(
"
../../../models/vectors
"
);
const
{
Workspace
}
=
require
(
"
../../../models/workspace
"
);
const
{
WorkspaceChats
}
=
require
(
"
../../../models/workspaceChats
"
);
const
{
convertToChatHistory
}
=
require
(
"
../../../utils/chats
"
);
const
{
convertToChatHistory
,
chatWithWorkspace
,
}
=
require
(
"
../../../utils/chats
"
);
const
{
getVectorDbClass
}
=
require
(
"
../../../utils/helpers
"
);
const
{
multiUserMode
,
reqBody
}
=
require
(
"
../../../utils/http
"
);
const
{
validApiKey
}
=
require
(
"
../../../utils/middleware/validApiKey
"
);
...
...
@@ -427,6 +430,78 @@ function apiWorkspaceEndpoints(app) {
}
}
);
app
.
post
(
"
/v1/workspace/:slug/chat
"
,
[
validApiKey
],
async
(
request
,
response
)
=>
{
/*
#swagger.tags = ['Workspaces']
#swagger.description = 'Execute a chat with a workspace'
#swagger.requestBody = {
description: 'prompt to send to the workspace and the type of conversation (query or chat).',
required: true,
type: 'object',
content: {
"application/json": {
example: {
message: "What is AnythingLLM?",
mode: "query | chat"
}
}
}
}
#swagger.responses[200] = {
content: {
"application/json": {
schema: {
type: 'object',
example: {
id: 'chat-uuid',
type: "abort | textResponse",
textResponse: "Response to your query",
sources: [{title: "anythingllm.txt", chunk: "This is a context chunk used in the answer of the prompt by the LLM,"}],
close: true,
error: "null | text string of the failure mode."
}
}
}
}
}
#swagger.responses[403] = {
schema: {
"$ref": "#/definitions/InvalidAPIKey"
}
}
*/
try
{
const
{
slug
}
=
request
.
params
;
const
{
message
,
mode
=
"
query
"
}
=
reqBody
(
request
);
const
workspace
=
await
Workspace
.
get
({
slug
});
if
(
!
workspace
)
{
response
.
sendStatus
(
400
).
end
();
return
;
}
const
result
=
await
chatWithWorkspace
(
workspace
,
message
,
mode
);
await
Telemetry
.
sendTelemetry
(
"
sent_chat
"
,
{
LLMSelection
:
process
.
env
.
LLM_PROVIDER
||
"
openai
"
,
VectorDbSelection
:
process
.
env
.
VECTOR_DB
||
"
pinecone
"
,
});
response
.
status
(
200
).
json
({
...
result
});
}
catch
(
e
)
{
response
.
status
(
500
).
json
({
id
:
uuidv4
(),
type
:
"
abort
"
,
textResponse
:
null
,
sources
:
[],
close
:
true
,
error
:
e
.
message
,
});
}
}
);
}
module
.
exports
=
{
apiWorkspaceEndpoints
};
This diff is collapsed.
Click to expand it.
server/swagger/openapi.json
+
84
−
0
View file @
3f5b4196
...
...
@@ -1531,6 +1531,90 @@
}
}
},
"/v1/workspace/{slug}/chat"
:
{
"post"
:
{
"tags"
:
[
"Workspaces"
],
"description"
:
"Execute a chat with a workspace"
,
"parameters"
:
[
{
"name"
:
"slug"
,
"in"
:
"path"
,
"required"
:
true
,
"schema"
:
{
"type"
:
"string"
}
},
{
"name"
:
"Authorization"
,
"in"
:
"header"
,
"schema"
:
{
"type"
:
"string"
}
}
],
"responses"
:
{
"200"
:
{
"description"
:
"OK"
,
"content"
:
{
"application/json"
:
{
"schema"
:
{
"type"
:
"object"
,
"example"
:
{
"id"
:
"chat-uuid"
,
"type"
:
"abort | textResponse"
,
"textResponse"
:
"Response to your query"
,
"sources"
:
[
{
"title"
:
"anythingllm.txt"
,
"chunk"
:
"This is a context chunk used in the answer of the prompt by the LLM,"
}
],
"close"
:
true
,
"error"
:
"null | text string of the failure mode."
}
}
}
}
},
"400"
:
{
"description"
:
"Bad Request"
},
"403"
:
{
"description"
:
"Forbidden"
,
"content"
:
{
"application/json"
:
{
"schema"
:
{
"$ref"
:
"#/components/schemas/InvalidAPIKey"
}
},
"application/xml"
:
{
"schema"
:
{
"$ref"
:
"#/components/schemas/InvalidAPIKey"
}
}
}
},
"500"
:
{
"description"
:
"Internal Server Error"
}
},
"requestBody"
:
{
"description"
:
"prompt to send to the workspace and the type of conversation (query or chat)."
,
"required"
:
true
,
"type"
:
"object"
,
"content"
:
{
"application/json"
:
{
"example"
:
{
"message"
:
"What is AnythingLLM?"
,
"mode"
:
"query | chat"
}
}
}
}
}
},
"/v1/system/env-dump"
:
{
"get"
:
{
"tags"
:
[
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment