mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-28 15:00:57 +03:00
add llamaindex
This commit is contained in:
@@ -8,7 +8,7 @@ import { DataSource } from 'typeorm'
|
||||
import { ICommonObject, IDatabaseEntity, IMessage, INodeData } from './Interface'
|
||||
import { AES, enc } from 'crypto-js'
|
||||
import { ChatMessageHistory } from 'langchain/memory'
|
||||
import { AIMessage, HumanMessage } from 'langchain/schema'
|
||||
import { AIMessage, HumanMessage, BaseMessage } from 'langchain/schema'
|
||||
|
||||
export const numberOrExpressionRegex = '^(\\d+\\.?\\d*|{{.*}})$' //return true if string consists only numbers OR expression {{}}
|
||||
export const notEmptyRegex = '(.|\\s)*\\S(.|\\s)*' //return true if string is not empty or blank
|
||||
@@ -587,3 +587,54 @@ export const convertSchemaToZod = (schema: string | object): ICommonObject => {
|
||||
throw new Error(e)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Flatten nested object
|
||||
* @param {ICommonObject} obj
|
||||
* @param {string} parentKey
|
||||
* @returns {ICommonObject}
|
||||
*/
|
||||
export const flattenObject = (obj: ICommonObject, parentKey?: string) => {
|
||||
let result: any = {}
|
||||
|
||||
Object.keys(obj).forEach((key) => {
|
||||
const value = obj[key]
|
||||
const _key = parentKey ? parentKey + '.' + key : key
|
||||
if (typeof value === 'object') {
|
||||
result = { ...result, ...flattenObject(value, _key) }
|
||||
} else {
|
||||
result[_key] = value
|
||||
}
|
||||
})
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert BaseMessage to IMessage
|
||||
* @param {ICommonObject} obj
|
||||
* @param {string} parentKey
|
||||
* @returns {ICommonObject}
|
||||
*/
|
||||
export const convertBaseMessagetoIMessage = (messages: BaseMessage[]): IMessage[] => {
|
||||
const formatmessages: IMessage[] = []
|
||||
for (const m of messages) {
|
||||
if (m._getType() === 'human') {
|
||||
formatmessages.push({
|
||||
message: m.content as string,
|
||||
type: 'userMessage'
|
||||
})
|
||||
} else if (m._getType() === 'ai') {
|
||||
formatmessages.push({
|
||||
message: m.content as string,
|
||||
type: 'apiMessage'
|
||||
})
|
||||
} else if (m._getType() === 'system') {
|
||||
formatmessages.push({
|
||||
message: m.content as string,
|
||||
type: 'apiMessage'
|
||||
})
|
||||
}
|
||||
}
|
||||
return formatmessages
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user