mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-23 01:00:22 +03:00
26444ac3ae
* Base changes for ServerSide Events (instead of socket.io) * lint fixes * adding of interface and separate methods for streaming events * lint * first draft, handles both internal and external prediction end points. * lint fixes * additional internal end point for streaming and associated changes * return streamresponse as true to build agent flow * 1) JSON formatting for internal events 2) other fixes * 1) convert internal event to metadata to maintain consistency with external response * fix action and metadata streaming * fix for error when agent flow is aborted * prevent subflows from streaming and other code cleanup * prevent streaming from enclosed tools * add fix for preventing chaintool streaming * update lock file * add open when hidden to sse * Streaming errors * Streaming errors * add fix for showing error message --------- Co-authored-by: Henry <hzj94@hotmail.com>
26 lines
910 B
TypeScript
26 lines
910 B
TypeScript
import { IServerSideEventStreamer } from '../../src'
|
|
|
|
export abstract class Moderation {
|
|
abstract checkForViolations(input: string): Promise<string>
|
|
}
|
|
|
|
export const checkInputs = async (inputModerations: Moderation[], input: string): Promise<string> => {
|
|
for (const moderation of inputModerations) {
|
|
input = await moderation.checkForViolations(input)
|
|
}
|
|
return input
|
|
}
|
|
|
|
// is this the correct location for this function?
|
|
// should we have a utils files that all node components can use?
|
|
export const streamResponse = (sseStreamer: IServerSideEventStreamer, chatId: string, response: string) => {
|
|
const result = response.split(/(\s+)/)
|
|
result.forEach((token: string, index: number) => {
|
|
if (index === 0) {
|
|
sseStreamer.streamStartEvent(chatId, token)
|
|
}
|
|
sseStreamer.streamTokenEvent(chatId, token)
|
|
})
|
|
sseStreamer.streamEndEvent(chatId)
|
|
}
|