mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-28 17:01:00 +03:00
modify addChatMessage
This commit is contained in:
@@ -2,6 +2,10 @@ import { ICommonObject, INode, INodeData as INodeDataFromComponent, INodeParams
|
||||
|
||||
export type MessageType = 'apiMessage' | 'userMessage'
|
||||
|
||||
export enum chatType {
|
||||
INTERNAL = 'INTERNAL',
|
||||
EXTERNAL = 'EXTERNAL'
|
||||
}
|
||||
/**
|
||||
* Databases
|
||||
*/
|
||||
|
||||
@@ -16,7 +16,8 @@ import {
|
||||
IReactFlowObject,
|
||||
INodeData,
|
||||
IDatabaseExport,
|
||||
ICredentialReturnResponse
|
||||
ICredentialReturnResponse,
|
||||
chatType
|
||||
} from './Interface'
|
||||
import {
|
||||
getNodeModulesPackagePath,
|
||||
@@ -404,12 +405,7 @@ export class App {
|
||||
// Add chatmessages for chatflowid
|
||||
this.app.post('/api/v1/chatmessage/:id', async (req: Request, res: Response) => {
|
||||
const body = req.body
|
||||
const newChatMessage = new ChatMessage()
|
||||
Object.assign(newChatMessage, body)
|
||||
|
||||
const chatmessage = this.AppDataSource.getRepository(ChatMessage).create(newChatMessage)
|
||||
const results = await this.AppDataSource.getRepository(ChatMessage).save(chatmessage)
|
||||
|
||||
const results = await this.addChatMessage(body)
|
||||
return res.json(results)
|
||||
})
|
||||
|
||||
@@ -818,6 +814,18 @@ export class App {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add Chat Message
|
||||
* @param {any} chatMessage
|
||||
*/
|
||||
async addChatMessage(chatMessage: any) {
|
||||
const newChatMessage = new ChatMessage()
|
||||
Object.assign(newChatMessage, chatMessage)
|
||||
|
||||
const chatmessage = this.AppDataSource.getRepository(ChatMessage).create(newChatMessage)
|
||||
return await this.AppDataSource.getRepository(ChatMessage).save(chatmessage)
|
||||
}
|
||||
|
||||
/**
|
||||
* Process Prediction
|
||||
* @param {Request} req
|
||||
@@ -844,6 +852,13 @@ export class App {
|
||||
await this.validateKey(req, res, chatflow)
|
||||
}
|
||||
|
||||
await this.addChatMessage({
|
||||
role: 'userMessage',
|
||||
content: incomingInput.question,
|
||||
chatflowid: chatflowid,
|
||||
chatType: isInternal ? chatType.INTERNAL : chatType.EXTERNAL
|
||||
})
|
||||
|
||||
let isStreamValid = false
|
||||
|
||||
const files = (req.files as any[]) || []
|
||||
@@ -991,6 +1006,15 @@ export class App {
|
||||
analytic: chatflow.analytic
|
||||
})
|
||||
|
||||
const apiMessage: any = {
|
||||
role: 'apiMessage',
|
||||
content: typeof result === 'string' ? result : result.text,
|
||||
chatflowid: chatflowid,
|
||||
chatType: isInternal ? chatType.INTERNAL : chatType.EXTERNAL
|
||||
}
|
||||
if (result?.sourceDocuments) apiMessage.sourceDocuments = JSON.stringify(result.sourceDocuments)
|
||||
await this.addChatMessage(apiMessage)
|
||||
|
||||
logger.debug(`[server]: Finished running ${nodeToExecuteData.label} (${nodeToExecuteData.id})`)
|
||||
return res.json(result)
|
||||
} catch (e: any) {
|
||||
|
||||
Reference in New Issue
Block a user