mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-28 21:00:58 +03:00
ResponsibleAI - Input Moderation - Renaming of files for better clarity and alignment to functionality
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
import { BaseLanguageModel } from 'langchain/base_language'
|
||||
import { Server } from 'socket.io'
|
||||
|
||||
export abstract class Moderation {
|
||||
abstract checkForViolations(llm: BaseLanguageModel, input: string): Promise<string>
|
||||
}
|
||||
|
||||
export const checkInputs = async (inputModerations: Moderation[], llm: BaseLanguageModel, input: string): Promise<string> => {
|
||||
for (const moderation of inputModerations) {
|
||||
input = await moderation.checkForViolations(llm, 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 = (isStreaming: any, response: string, socketIO: Server, socketIOClientId: string) => {
|
||||
if (isStreaming) {
|
||||
const result = response.split(/(\s+)/)
|
||||
result.forEach((token: string, index: number) => {
|
||||
if (index === 0) {
|
||||
socketIO.to(socketIOClientId).emit('start', token)
|
||||
}
|
||||
socketIO.to(socketIOClientId).emit('token', token)
|
||||
})
|
||||
socketIO.to(socketIOClientId).emit('end')
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user