Support attachments in developer API (#2373)
* support attachments in developer api * lint --------- Co-authored-by: Timothy Carambat <rambat1010@gmail.com>
This commit is contained in:
parent
e2195a96d1
commit
e6c4eb3f1c
@ -546,7 +546,14 @@ function apiWorkspaceEndpoints(app) {
|
|||||||
example: {
|
example: {
|
||||||
message: "What is AnythingLLM?",
|
message: "What is AnythingLLM?",
|
||||||
mode: "query | chat",
|
mode: "query | chat",
|
||||||
sessionId: "identifier-to-partition-chats-by-external-id"
|
sessionId: "identifier-to-partition-chats-by-external-id",
|
||||||
|
attachments: [
|
||||||
|
{
|
||||||
|
name: "image.png",
|
||||||
|
mime: "image/png",
|
||||||
|
contentString: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA..."
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -576,7 +583,12 @@ function apiWorkspaceEndpoints(app) {
|
|||||||
*/
|
*/
|
||||||
try {
|
try {
|
||||||
const { slug } = request.params;
|
const { slug } = request.params;
|
||||||
const { message, mode = "query", sessionId = null } = reqBody(request);
|
const {
|
||||||
|
message,
|
||||||
|
mode = "query",
|
||||||
|
sessionId = null,
|
||||||
|
attachments = [],
|
||||||
|
} = reqBody(request);
|
||||||
const workspace = await Workspace.get({ slug: String(slug) });
|
const workspace = await Workspace.get({ slug: String(slug) });
|
||||||
|
|
||||||
if (!workspace) {
|
if (!workspace) {
|
||||||
@ -612,6 +624,7 @@ function apiWorkspaceEndpoints(app) {
|
|||||||
user: null,
|
user: null,
|
||||||
thread: null,
|
thread: null,
|
||||||
sessionId: !!sessionId ? String(sessionId) : null,
|
sessionId: !!sessionId ? String(sessionId) : null,
|
||||||
|
attachments,
|
||||||
});
|
});
|
||||||
|
|
||||||
await Telemetry.sendTelemetry("sent_chat", {
|
await Telemetry.sendTelemetry("sent_chat", {
|
||||||
@ -655,7 +668,14 @@ function apiWorkspaceEndpoints(app) {
|
|||||||
example: {
|
example: {
|
||||||
message: "What is AnythingLLM?",
|
message: "What is AnythingLLM?",
|
||||||
mode: "query | chat",
|
mode: "query | chat",
|
||||||
sessionId: "identifier-to-partition-chats-by-external-id"
|
sessionId: "identifier-to-partition-chats-by-external-id",
|
||||||
|
attachments: [
|
||||||
|
{
|
||||||
|
name: "image.png",
|
||||||
|
mime: "image/png",
|
||||||
|
contentString: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA..."
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -706,7 +726,12 @@ function apiWorkspaceEndpoints(app) {
|
|||||||
*/
|
*/
|
||||||
try {
|
try {
|
||||||
const { slug } = request.params;
|
const { slug } = request.params;
|
||||||
const { message, mode = "query", sessionId = null } = reqBody(request);
|
const {
|
||||||
|
message,
|
||||||
|
mode = "query",
|
||||||
|
sessionId = null,
|
||||||
|
attachments = [],
|
||||||
|
} = reqBody(request);
|
||||||
const workspace = await Workspace.get({ slug: String(slug) });
|
const workspace = await Workspace.get({ slug: String(slug) });
|
||||||
|
|
||||||
if (!workspace) {
|
if (!workspace) {
|
||||||
@ -749,6 +774,7 @@ function apiWorkspaceEndpoints(app) {
|
|||||||
user: null,
|
user: null,
|
||||||
thread: null,
|
thread: null,
|
||||||
sessionId: !!sessionId ? String(sessionId) : null,
|
sessionId: !!sessionId ? String(sessionId) : null,
|
||||||
|
attachments,
|
||||||
});
|
});
|
||||||
await Telemetry.sendTelemetry("sent_chat", {
|
await Telemetry.sendTelemetry("sent_chat", {
|
||||||
LLMSelection:
|
LLMSelection:
|
||||||
|
|||||||
@ -1958,7 +1958,14 @@
|
|||||||
"example": {
|
"example": {
|
||||||
"message": "What is AnythingLLM?",
|
"message": "What is AnythingLLM?",
|
||||||
"mode": "query | chat",
|
"mode": "query | chat",
|
||||||
"sessionId": "identifier-to-partition-chats-by-external-id"
|
"sessionId": "identifier-to-partition-chats-by-external-id",
|
||||||
|
"attachments": [
|
||||||
|
{
|
||||||
|
"name": "image.png",
|
||||||
|
"mime": "image/png",
|
||||||
|
"contentString": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA..."
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2053,7 +2060,14 @@
|
|||||||
"example": {
|
"example": {
|
||||||
"message": "What is AnythingLLM?",
|
"message": "What is AnythingLLM?",
|
||||||
"mode": "query | chat",
|
"mode": "query | chat",
|
||||||
"sessionId": "identifier-to-partition-chats-by-external-id"
|
"sessionId": "identifier-to-partition-chats-by-external-id",
|
||||||
|
"attachments": [
|
||||||
|
{
|
||||||
|
"name": "image.png",
|
||||||
|
"mime": "image/png",
|
||||||
|
"contentString": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA..."
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -29,6 +29,7 @@ const { Telemetry } = require("../../models/telemetry");
|
|||||||
* user: import("@prisma/client").users|null,
|
* user: import("@prisma/client").users|null,
|
||||||
* thread: import("@prisma/client").workspace_threads|null,
|
* thread: import("@prisma/client").workspace_threads|null,
|
||||||
* sessionId: string|null,
|
* sessionId: string|null,
|
||||||
|
* attachments: { name: string; mime: string; contentString: string }[],
|
||||||
* }} parameters
|
* }} parameters
|
||||||
* @returns {Promise<ResponseObject>}
|
* @returns {Promise<ResponseObject>}
|
||||||
*/
|
*/
|
||||||
@ -39,6 +40,7 @@ async function chatSync({
|
|||||||
user = null,
|
user = null,
|
||||||
thread = null,
|
thread = null,
|
||||||
sessionId = null,
|
sessionId = null,
|
||||||
|
attachments = [],
|
||||||
}) {
|
}) {
|
||||||
const uuid = uuidv4();
|
const uuid = uuidv4();
|
||||||
const chatMode = mode ?? "chat";
|
const chatMode = mode ?? "chat";
|
||||||
@ -251,6 +253,7 @@ async function chatSync({
|
|||||||
userPrompt: message,
|
userPrompt: message,
|
||||||
contextTexts,
|
contextTexts,
|
||||||
chatHistory,
|
chatHistory,
|
||||||
|
attachments,
|
||||||
},
|
},
|
||||||
rawHistory
|
rawHistory
|
||||||
);
|
);
|
||||||
@ -301,6 +304,7 @@ async function chatSync({
|
|||||||
* user: import("@prisma/client").users|null,
|
* user: import("@prisma/client").users|null,
|
||||||
* thread: import("@prisma/client").workspace_threads|null,
|
* thread: import("@prisma/client").workspace_threads|null,
|
||||||
* sessionId: string|null,
|
* sessionId: string|null,
|
||||||
|
* attachments: { name: string; mime: string; contentString: string }[],
|
||||||
* }} parameters
|
* }} parameters
|
||||||
* @returns {Promise<VoidFunction>}
|
* @returns {Promise<VoidFunction>}
|
||||||
*/
|
*/
|
||||||
@ -312,6 +316,7 @@ async function streamChat({
|
|||||||
user = null,
|
user = null,
|
||||||
thread = null,
|
thread = null,
|
||||||
sessionId = null,
|
sessionId = null,
|
||||||
|
attachments = [],
|
||||||
}) {
|
}) {
|
||||||
const uuid = uuidv4();
|
const uuid = uuidv4();
|
||||||
const chatMode = mode ?? "chat";
|
const chatMode = mode ?? "chat";
|
||||||
@ -536,6 +541,7 @@ async function streamChat({
|
|||||||
userPrompt: message,
|
userPrompt: message,
|
||||||
contextTexts,
|
contextTexts,
|
||||||
chatHistory,
|
chatHistory,
|
||||||
|
attachments,
|
||||||
},
|
},
|
||||||
rawHistory
|
rawHistory
|
||||||
);
|
);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user