mirror of
https://github.com/Mintplex-Labs/anything-llm.git
synced 2024-11-16 03:10:31 +01:00
2e813846dc
* WIP agent support * move agent folder * wip frontend socket * checkpoint * fix schema * Checkpoint for plugins and AgentHandler * refactor plugins and agent arch * agent error reporting and handling * add frontend elements for agents in prompt input * WIP integrations for agents * enable web-search agent config from frontend * persist chat history * update alert * update migration remove console logs update close state for agent invocations * add examples to dockerignore Extract statusResponse to its own component * update close method * wrap scraping rejections * add RAG search as funciton * Add telem and link highlight * chat support * patch memory * Add rechart as a plugin option * Toggles for abilites of default agent (system wide) Validate values for agent skills Enable dynamic loading of skills UI for toggle of skills * add UI for toggle of configs for agent * toggle WS or WSS protocol * update NGNIX proxy pass * move components around and capture failed websocket creation * fix name * tmp docker image * reset workflow * safety mark functions * telem on tool calls * remove hardcode short circuit * separate web-browser from scrape * extract summarizer to util add abort handlers and controller for langchain stuff so socket close kills process * langchain summarize verbose when in dev * chart styling improvements + add title to chart * fix legend from being cutoff in chart downloads * remove cursor blink --------- Co-authored-by: shatfield4 <seanhatfield5@gmail.com>
85 lines
2.9 KiB
JavaScript
85 lines
2.9 KiB
JavaScript
const { WorkspaceChats } = require("../../../../models/workspaceChats");
|
|
|
|
/**
|
|
* Plugin to save chat history to AnythingLLM DB.
|
|
*/
|
|
const chatHistory = {
|
|
name: "chat-history",
|
|
startupConfig: {
|
|
params: {},
|
|
},
|
|
plugin: function () {
|
|
return {
|
|
name: this.name,
|
|
setup: function (aibitat) {
|
|
aibitat.onMessage(async () => {
|
|
try {
|
|
const lastResponses = aibitat.chats.slice(-2);
|
|
if (lastResponses.length !== 2) return;
|
|
const [prev, last] = lastResponses;
|
|
|
|
// We need a full conversation reply with prev being from
|
|
// the USER and the last being from anyone other than the user.
|
|
if (prev.from !== "USER" || last.from === "USER") return;
|
|
|
|
// If we have a post-reply flow we should save the chat using this special flow
|
|
// so that post save cleanup and other unique properties can be run as opposed to regular chat.
|
|
if (aibitat.hasOwnProperty("_replySpecialAttributes")) {
|
|
await this._storeSpecial(aibitat, {
|
|
prompt: prev.content,
|
|
response: last.content,
|
|
options: aibitat._replySpecialAttributes,
|
|
});
|
|
delete aibitat._replySpecialAttributes;
|
|
return;
|
|
}
|
|
|
|
await this._store(aibitat, {
|
|
prompt: prev.content,
|
|
response: last.content,
|
|
});
|
|
} catch {}
|
|
});
|
|
},
|
|
_store: async function (aibitat, { prompt, response } = {}) {
|
|
const invocation = aibitat.handlerProps.invocation;
|
|
await WorkspaceChats.new({
|
|
workspaceId: Number(invocation.workspace_id),
|
|
prompt,
|
|
response: {
|
|
text: response,
|
|
sources: [],
|
|
type: "chat",
|
|
},
|
|
user: { id: invocation?.user_id || null },
|
|
threadId: invocation?.thread_id || null,
|
|
});
|
|
},
|
|
_storeSpecial: async function (
|
|
aibitat,
|
|
{ prompt, response, options = {} } = {}
|
|
) {
|
|
const invocation = aibitat.handlerProps.invocation;
|
|
await WorkspaceChats.new({
|
|
workspaceId: Number(invocation.workspace_id),
|
|
prompt,
|
|
response: {
|
|
sources: options?.sources ?? [],
|
|
// when we have a _storeSpecial called the options param can include a storedResponse() function
|
|
// that will override the text property to store extra information in, depending on the special type of chat.
|
|
text: options.hasOwnProperty("storedResponse")
|
|
? options.storedResponse(response)
|
|
: response,
|
|
type: options?.saveAsType ?? "chat",
|
|
},
|
|
user: { id: invocation?.user_id || null },
|
|
threadId: invocation?.thread_id || null,
|
|
});
|
|
options?.postSave();
|
|
},
|
|
};
|
|
},
|
|
};
|
|
|
|
module.exports = { chatHistory };
|