mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-28 23:01:09 +03:00
only emit token when parentId is undefined
This commit is contained in:
@@ -177,21 +177,17 @@ export class CustomChainHandler extends BaseCallbackHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
handleLLMEnd() {
|
handleLLMEnd() {
|
||||||
/* send the end event from handleChainEnd */
|
this.socketIO.to(this.socketIOClientId).emit('end')
|
||||||
// this.socketIO.to(this.socketIOClientId).emit('end')
|
|
||||||
}
|
}
|
||||||
|
|
||||||
handleChainEnd(outputs: ChainValues): void | Promise<void> {
|
handleChainEnd(outputs: ChainValues, _: string, parentRunId?: string): void | Promise<void> {
|
||||||
if (this.returnSourceDocuments) {
|
|
||||||
this.socketIO.to(this.socketIOClientId).emit('sourceDocuments', outputs?.sourceDocuments)
|
|
||||||
}
|
|
||||||
/*
|
/*
|
||||||
Langchain does not call handleLLMStart, handleLLMEnd, handleLLMNewToken when the chain is cached.
|
Langchain does not call handleLLMStart, handleLLMEnd, handleLLMNewToken when the chain is cached.
|
||||||
Callback Order is "Chain Start -> LLM Start --> LLM Token --> LLM End -> Chain End" for normal responses.
|
Callback Order is "Chain Start -> LLM Start --> LLM Token --> LLM End -> Chain End" for normal responses.
|
||||||
Callback Order is "Chain Start -> Chain End" for cached responses.
|
Callback Order is "Chain Start -> Chain End" for cached responses.
|
||||||
*/
|
*/
|
||||||
if (this.cachedResponse) {
|
if (this.cachedResponse && parentRunId === undefined) {
|
||||||
const cachedValue: string = outputs.text ?? outputs.response ?? outputs.output ?? ''
|
const cachedValue = outputs.text ?? outputs.response ?? outputs.output ?? outputs.output_text
|
||||||
//split at whitespace, and keep the whitespace. This is to preserve the original formatting.
|
//split at whitespace, and keep the whitespace. This is to preserve the original formatting.
|
||||||
const result = cachedValue.split(/(\s+)/)
|
const result = cachedValue.split(/(\s+)/)
|
||||||
result.forEach((token: string, index: number) => {
|
result.forEach((token: string, index: number) => {
|
||||||
@@ -200,8 +196,15 @@ export class CustomChainHandler extends BaseCallbackHandler {
|
|||||||
}
|
}
|
||||||
this.socketIO.to(this.socketIOClientId).emit('token', token)
|
this.socketIO.to(this.socketIOClientId).emit('token', token)
|
||||||
})
|
})
|
||||||
|
if (this.returnSourceDocuments) {
|
||||||
|
this.socketIO.to(this.socketIOClientId).emit('sourceDocuments', outputs?.sourceDocuments)
|
||||||
|
}
|
||||||
|
this.socketIO.to(this.socketIOClientId).emit('end')
|
||||||
|
} else {
|
||||||
|
if (this.returnSourceDocuments) {
|
||||||
|
this.socketIO.to(this.socketIOClientId).emit('sourceDocuments', outputs?.sourceDocuments)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
this.socketIO.to(this.socketIOClientId).emit('end')
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user