return JSON output in the chat

This commit is contained in:
Henry
2023-10-29 10:27:04 +00:00
parent aa2075d60b
commit 8857530f29
6 changed files with 33 additions and 27 deletions
+4 -1
View File
@@ -152,13 +152,15 @@ export class CustomChainHandler extends BaseCallbackHandler {
skipK = 0 // Skip streaming for first K numbers of handleLLMStart
returnSourceDocuments = false
cachedResponse = true
isOutputParser = false
constructor(socketIO: Server, socketIOClientId: string, skipK?: number, returnSourceDocuments?: boolean) {
constructor(socketIO: Server, socketIOClientId: string, skipK?: number, returnSourceDocuments?: boolean, isOutputParser?: boolean) {
super()
this.socketIO = socketIO
this.socketIOClientId = socketIOClientId
this.skipK = skipK ?? this.skipK
this.returnSourceDocuments = returnSourceDocuments ?? this.returnSourceDocuments
this.isOutputParser = isOutputParser ?? this.isOutputParser
}
handleLLMStart() {
@@ -171,6 +173,7 @@ export class CustomChainHandler extends BaseCallbackHandler {
if (!this.isLLMStarted) {
this.isLLMStarted = true
this.socketIO.to(this.socketIOClientId).emit('start', token)
if (this.isOutputParser) this.socketIO.to(this.socketIOClientId).emit('token', '```json')
}
this.socketIO.to(this.socketIOClientId).emit('token', token)
}