mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-28 17:01:00 +03:00
Feature/lang graph (#2319)
* add langgraph * datasource: initial commit * datasource: datasource details and chunks * datasource: Document Store Node * more changes * Document Store - Base functionality * Document Store Loader Component * Document Store Loader Component * before merging the modularity PR * after merging the modularity PR * preview mode * initial draft PR * fixes * minor updates and fixes * preview with loader and splitter * preview with credential * show stored chunks * preview update... * edit config * save, preview and other changes * save, preview and other changes * save, process and other changes * save, process and other changes * alpha1 - for internal testing * rerouting urls * bug fix on new leader create * pagination support for chunks * delete document store * Update pnpm-lock.yaml * doc store card view * Update store files to use updated storage functions, Document Store Table View and other changes * ui changes * add expanded chunk dialog, improve ui * change throw Error to InternalError * Bug Fixes and removal of subFolder, adding of view chunks for store * lint fixes * merge changes * DocumentStoreStatus component * ui changes for doc store * add remove metadata key field, add custom document loader * add chatflows used doc store chips * add types/interfaces to DocumentStore Services * document loader list dialog title bar color change * update interfaces * Whereused Chatflow Name and Added chunkNo to retain order of created chunks. * use typeorm order chunkNo, ui changes * update tabler icons react * cleanup agents * add pysandbox tool * add abort functionality, loading next agent * add empty view svg * update chatflow tool with chatId * rename to agentflows * update worker for prompt input values * update dashboard to agentflows, agentcanvas * fix marketplace use template * add agentflow templates * resolve merge conflict * update baseURL --------- Co-authored-by: vinodkiran <vinodkiran@usa.net> Co-authored-by: Vinod Paidimarry <vinodkiran@outlook.in>
This commit is contained in:
@@ -1,3 +1,7 @@
|
||||
import { BaseMessage } from '@langchain/core/messages'
|
||||
import { BufferMemory, BufferWindowMemory, ConversationSummaryMemory, ConversationSummaryBufferMemory } from 'langchain/memory'
|
||||
import { Moderation } from '../nodes/moderation/Moderation'
|
||||
|
||||
/**
|
||||
* Types
|
||||
*/
|
||||
@@ -149,6 +153,38 @@ export interface IUsedTool {
|
||||
toolOutput: string | object
|
||||
}
|
||||
|
||||
export interface IMultiAgentNode {
|
||||
node: any
|
||||
name: string
|
||||
label: string
|
||||
type: 'supervisor' | 'worker'
|
||||
llm?: any
|
||||
parentSupervisorName?: string
|
||||
workers?: string[]
|
||||
workerPrompt?: string
|
||||
workerInputVariables?: string[]
|
||||
recursionLimit?: number
|
||||
moderations?: Moderation[]
|
||||
multiModalMessageContent?: MessageContentImageUrl[]
|
||||
}
|
||||
|
||||
export interface ITeamState {
|
||||
messages: {
|
||||
value: (x: BaseMessage[], y: BaseMessage[]) => BaseMessage[]
|
||||
default: () => BaseMessage[]
|
||||
}
|
||||
team_members: string[]
|
||||
next: string
|
||||
instructions: string
|
||||
}
|
||||
|
||||
export interface IAgentReasoning {
|
||||
agentName: string
|
||||
messages: string[]
|
||||
next: string
|
||||
instructions: string
|
||||
}
|
||||
|
||||
export interface IFileUpload {
|
||||
data?: string
|
||||
type: string
|
||||
@@ -239,8 +275,6 @@ export class VectorStoreRetriever {
|
||||
/**
|
||||
* Implement abstract classes and interface for memory
|
||||
*/
|
||||
import { BaseMessage } from '@langchain/core/messages'
|
||||
import { BufferMemory, BufferWindowMemory, ConversationSummaryMemory, ConversationSummaryBufferMemory } from 'langchain/memory'
|
||||
|
||||
export interface MemoryMethods {
|
||||
getChatMessages(
|
||||
|
||||
@@ -3,7 +3,7 @@ import { ChainValues } from '@langchain/core/utils/types'
|
||||
import { AgentStep, AgentAction } from '@langchain/core/agents'
|
||||
import { BaseMessage, FunctionMessage, AIMessage, isBaseMessage } from '@langchain/core/messages'
|
||||
import { ToolCall } from '@langchain/core/messages/tool'
|
||||
import { OutputParserException, BaseOutputParser } from '@langchain/core/output_parsers'
|
||||
import { OutputParserException, BaseOutputParser, BaseLLMOutputParser } from '@langchain/core/output_parsers'
|
||||
import { BaseLanguageModel } from '@langchain/core/language_models/base'
|
||||
import { CallbackManager, CallbackManagerForChainRun, Callbacks } from '@langchain/core/callbacks/manager'
|
||||
import { ToolInputParsingException, Tool, StructuredToolInterface } from '@langchain/core/tools'
|
||||
@@ -25,12 +25,11 @@ import { formatLogToString } from 'langchain/agents/format_scratchpad/log'
|
||||
import { IUsedTool } from './Interface'
|
||||
|
||||
export const SOURCE_DOCUMENTS_PREFIX = '\n\n----FLOWISE_SOURCE_DOCUMENTS----\n\n'
|
||||
type AgentFinish = {
|
||||
export type AgentFinish = {
|
||||
returnValues: Record<string, any>
|
||||
log: string
|
||||
}
|
||||
type AgentExecutorOutput = ChainValues
|
||||
|
||||
interface AgentExecutorIteratorInput {
|
||||
agentExecutor: AgentExecutor
|
||||
inputs: Record<string, string>
|
||||
@@ -351,7 +350,6 @@ export class AgentExecutor extends BaseChain<ChainValues, AgentExecutorOutput> {
|
||||
const additional = await this.agent.prepareForOutput(returnValues, steps)
|
||||
if (sourceDocuments.length) additional.sourceDocuments = flatten(sourceDocuments)
|
||||
if (usedTools.length) additional.usedTools = usedTools
|
||||
|
||||
if (this.returnIntermediateSteps) {
|
||||
return { ...returnValues, intermediateSteps: steps, ...additional }
|
||||
}
|
||||
@@ -829,7 +827,7 @@ export class XMLAgentOutputParser extends AgentActionOutputParser {
|
||||
|
||||
abstract class AgentMultiActionOutputParser extends BaseOutputParser<AgentAction[] | AgentFinish> {}
|
||||
|
||||
type ToolsAgentAction = AgentAction & {
|
||||
export type ToolsAgentAction = AgentAction & {
|
||||
toolCallId: string
|
||||
messageLog?: BaseMessage[]
|
||||
}
|
||||
@@ -898,3 +896,106 @@ export class ToolCallingAgentOutputParser extends AgentMultiActionOutputParser {
|
||||
throw new Error('getFormatInstructions not implemented inside ToolCallingAgentOutputParser.')
|
||||
}
|
||||
}
|
||||
|
||||
export type ParsedToolCall = {
|
||||
id?: string
|
||||
|
||||
type: string
|
||||
|
||||
args: Record<string, any>
|
||||
|
||||
/** @deprecated Use `type` instead. Will be removed in 0.2.0. */
|
||||
name: string
|
||||
|
||||
/** @deprecated Use `args` instead. Will be removed in 0.2.0. */
|
||||
arguments: Record<string, any>
|
||||
}
|
||||
|
||||
export type JsonOutputToolsParserParams = {
|
||||
/** Whether to return the tool call id. */
|
||||
returnId?: boolean
|
||||
}
|
||||
|
||||
export class JsonOutputToolsParser extends BaseLLMOutputParser<ParsedToolCall[]> {
|
||||
static lc_name() {
|
||||
return 'JsonOutputToolsParser'
|
||||
}
|
||||
|
||||
returnId = false
|
||||
|
||||
lc_namespace = ['langchain', 'output_parsers', 'openai_tools']
|
||||
|
||||
lc_serializable = true
|
||||
|
||||
constructor(fields?: JsonOutputToolsParserParams) {
|
||||
super(fields)
|
||||
this.returnId = fields?.returnId ?? this.returnId
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the output and returns a JSON object. If `argsOnly` is true,
|
||||
* only the arguments of the function call are returned.
|
||||
* @param generations The output of the LLM to parse.
|
||||
* @returns A JSON object representation of the function call or its arguments.
|
||||
*/
|
||||
async parseResult(generations: ChatGeneration[]): Promise<ParsedToolCall[]> {
|
||||
const toolCalls = generations[0].message.additional_kwargs.tool_calls
|
||||
const parsedToolCalls = []
|
||||
|
||||
if (!toolCalls) {
|
||||
// @ts-expect-error name and arguemnts are defined by Object.defineProperty
|
||||
const parsedToolCall: ParsedToolCall = {
|
||||
type: 'undefined',
|
||||
args: {}
|
||||
}
|
||||
|
||||
// backward-compatibility with previous
|
||||
// versions of Langchain JS, which uses `name` and `arguments`
|
||||
Object.defineProperty(parsedToolCall, 'name', {
|
||||
get() {
|
||||
return this.type
|
||||
}
|
||||
})
|
||||
|
||||
Object.defineProperty(parsedToolCall, 'arguments', {
|
||||
get() {
|
||||
return this.args
|
||||
}
|
||||
})
|
||||
|
||||
parsedToolCalls.push(parsedToolCall)
|
||||
}
|
||||
|
||||
const clonedToolCalls = JSON.parse(JSON.stringify(toolCalls))
|
||||
for (const toolCall of clonedToolCalls) {
|
||||
if (toolCall.function !== undefined) {
|
||||
// @ts-expect-error name and arguemnts are defined by Object.defineProperty
|
||||
const parsedToolCall: ParsedToolCall = {
|
||||
type: toolCall.function.name,
|
||||
args: JSON.parse(toolCall.function.arguments)
|
||||
}
|
||||
|
||||
if (this.returnId) {
|
||||
parsedToolCall.id = toolCall.id
|
||||
}
|
||||
|
||||
// backward-compatibility with previous
|
||||
// versions of Langchain JS, which uses `name` and `arguments`
|
||||
Object.defineProperty(parsedToolCall, 'name', {
|
||||
get() {
|
||||
return this.type
|
||||
}
|
||||
})
|
||||
|
||||
Object.defineProperty(parsedToolCall, 'arguments', {
|
||||
get() {
|
||||
return this.args
|
||||
}
|
||||
})
|
||||
|
||||
parsedToolCalls.push(parsedToolCall)
|
||||
}
|
||||
}
|
||||
return parsedToolCalls
|
||||
}
|
||||
}
|
||||
|
||||
@@ -195,7 +195,7 @@ export class CustomChainHandler extends BaseCallbackHandler {
|
||||
Callback Order is "Chain Start -> Chain End" for cached responses.
|
||||
*/
|
||||
if (this.cachedResponse && parentRunId === undefined) {
|
||||
const cachedValue = outputs.text ?? outputs.response ?? outputs.output ?? outputs.output_text
|
||||
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.
|
||||
const result = cachedValue.split(/(\s+)/)
|
||||
result.forEach((token: string, index: number) => {
|
||||
|
||||
@@ -8,3 +8,4 @@ export * from './Interface'
|
||||
export * from './utils'
|
||||
export * from './speechToText'
|
||||
export * from './storageUtils'
|
||||
export * from './handler'
|
||||
|
||||
Reference in New Issue
Block a user