Merge pull request #149 from FlowiseAI/feature/Streaming

Feature/Streaming
This commit is contained in:
Ong Chung Yau
2023-05-26 09:01:40 +07:00
committed by GitHub
29 changed files with 902 additions and 301 deletions
@@ -1,6 +1,6 @@
import { ICommonObject, IMessage, INode, INodeData, INodeParams } from '../../../src/Interface'
import { ConversationChain } from 'langchain/chains'
import { getBaseClasses } from '../../../src/utils'
import { CustomChainHandler, getBaseClasses } from '../../../src/utils'
import { ChatPromptTemplate, HumanMessagePromptTemplate, MessagesPlaceholder, SystemMessagePromptTemplate } from 'langchain/prompts'
import { BufferMemory, ChatMessageHistory } from 'langchain/memory'
import { BaseChatModel } from 'langchain/chat_models/base'
@@ -90,8 +90,14 @@ class ConversationChain_Chains implements INode {
chain.memory = memory
}
const res = await chain.call({ input })
return res?.response
if (options.socketIO && options.socketIOClientId) {
const handler = new CustomChainHandler(options.socketIO, options.socketIOClientId)
const res = await chain.call({ input }, [handler])
return res?.response
} else {
const res = await chain.call({ input })
return res?.text
}
}
}