Merge branch 'main' into feature/Credential

# Conflicts:
#	packages/components/src/utils.ts
#	packages/server/src/ChildProcess.ts
This commit is contained in:
Henry
2023-07-15 14:30:50 +01:00
34 changed files with 509 additions and 209 deletions
+2 -46
View File
@@ -3,9 +3,6 @@ import { load } from 'cheerio'
import * as fs from 'fs'
import * as path from 'path'
import { JSDOM } from 'jsdom'
import { BaseCallbackHandler } from 'langchain/callbacks'
import { Server } from 'socket.io'
import { ChainValues } from 'langchain/dist/schema'
import { DataSource } from 'typeorm'
import { ICommonObject, IDatabaseEntity, INodeData } from './Interface'
import { AES, enc } from 'crypto-js'
@@ -436,50 +433,9 @@ export const getCredentialParam = (paramName: string, credentialData: ICommonObj
return (nodeData.inputs as ICommonObject)[paramName] ?? credentialData[paramName]
}
/**
* Custom chain handler class
/*
* List of dependencies allowed to be import in vm2
*/
export class CustomChainHandler extends BaseCallbackHandler {
name = 'custom_chain_handler'
isLLMStarted = false
socketIO: Server
socketIOClientId = ''
skipK = 0 // Skip streaming for first K numbers of handleLLMStart
returnSourceDocuments = false
constructor(socketIO: Server, socketIOClientId: string, skipK?: number, returnSourceDocuments?: boolean) {
super()
this.socketIO = socketIO
this.socketIOClientId = socketIOClientId
this.skipK = skipK ?? this.skipK
this.returnSourceDocuments = returnSourceDocuments ?? this.returnSourceDocuments
}
handleLLMStart() {
if (this.skipK > 0) this.skipK -= 1
}
handleLLMNewToken(token: string) {
if (this.skipK === 0) {
if (!this.isLLMStarted) {
this.isLLMStarted = true
this.socketIO.to(this.socketIOClientId).emit('start', token)
}
this.socketIO.to(this.socketIOClientId).emit('token', token)
}
}
handleLLMEnd() {
this.socketIO.to(this.socketIOClientId).emit('end')
}
handleChainEnd(outputs: ChainValues): void | Promise<void> {
if (this.returnSourceDocuments) {
this.socketIO.to(this.socketIOClientId).emit('sourceDocuments', outputs?.sourceDocuments)
}
}
}
export const availableDependencies = [
'@dqbd/tiktoken',
'@getzep/zep-js',