Skip to content

Commit

Permalink
add streaming handler to MultiChains
Browse files Browse the repository at this point in the history
  • Loading branch information
HenryHengZJ committed May 26, 2023
1 parent 2968dcc commit a4727c1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BaseLanguageModel } from 'langchain/base_language'
import { INode, INodeData, INodeParams, PromptRetriever } from '../../../src/Interface'
import { getBaseClasses } from '../../../src/utils'
import { ICommonObject, INode, INodeData, INodeParams, PromptRetriever } from '../../../src/Interface'
import { CustomChainHandler, getBaseClasses } from '../../../src/utils'
import { MultiPromptChain } from 'langchain/chains'

class MultiPromptChain_Chains implements INode {
Expand Down Expand Up @@ -56,12 +56,18 @@ class MultiPromptChain_Chains implements INode {
return chain
}

async run(nodeData: INodeData, input: string): Promise<string> {
async run(nodeData: INodeData, input: string, options: ICommonObject): Promise<string> {
const chain = nodeData.instance as MultiPromptChain
const obj = { input }

const res = await chain.call({ input })

return res?.text
if (options.socketIO && options.socketIOClientId) {
const handler = new CustomChainHandler(options.socketIO, options.socketIOClientId)
const res = await chain.call(obj, [handler])
return res?.text
} else {
const res = await chain.call(obj)
return res?.text
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BaseLanguageModel } from 'langchain/base_language'
import { INode, INodeData, INodeParams, VectorStoreRetriever } from '../../../src/Interface'
import { getBaseClasses } from '../../../src/utils'
import { ICommonObject, INode, INodeData, INodeParams, VectorStoreRetriever } from '../../../src/Interface'
import { CustomChainHandler, getBaseClasses } from '../../../src/utils'
import { MultiRetrievalQAChain } from 'langchain/chains'

class MultiRetrievalQAChain_Chains implements INode {
Expand Down Expand Up @@ -56,12 +56,18 @@ class MultiRetrievalQAChain_Chains implements INode {
return chain
}

async run(nodeData: INodeData, input: string): Promise<string> {
async run(nodeData: INodeData, input: string, options: ICommonObject): Promise<string> {
const chain = nodeData.instance as MultiRetrievalQAChain
const obj = { input }

const res = await chain.call({ input })

return res?.text
if (options.socketIO && options.socketIOClientId) {
const handler = new CustomChainHandler(options.socketIO, options.socketIOClientId)
const res = await chain.call(obj, [handler])
return res?.text
} else {
const res = await chain.call(obj)
return res?.text
}
}
}

Expand Down

0 comments on commit a4727c1

Please sign in to comment.