Feature/Code Interpreter (#3183)

* Base changes for ServerSide Events (instead of socket.io)

* lint fixes

* adding of interface and separate methods for streaming events

* lint

* first draft, handles both internal and external prediction end points.

* lint fixes

* additional internal end point for streaming and associated changes

* return streamresponse as true to build agent flow

* 1) JSON formatting for internal events
2) other fixes

* 1) convert internal event to metadata to maintain consistency with external response

* fix action and metadata streaming

* fix for error when agent flow is aborted

* prevent subflows from streaming and other code cleanup

* prevent streaming from enclosed tools

* add fix for preventing chaintool streaming

* update lock file

* add open when hidden to sse

* Streaming errors

* Streaming errors

* add fix for showing error message

* add code interpreter

* add artifacts to view message dialog

* Update pnpm-lock.yaml

---------

Co-authored-by: Vinod Paidimarry <vinodkiran@outlook.in>
This commit is contained in:
Henry Heng
2024-09-17 08:44:56 +01:00
committed by GitHub
parent 26444ac3ae
commit b02f279e9d
21 changed files with 729 additions and 333 deletions
@@ -154,6 +154,7 @@ export const buildAgentGraph = async (
let finalAction: IAction = {}
let totalSourceDocuments: IDocument[] = []
let totalUsedTools: IUsedTool[] = []
let totalArtifacts: ICommonObject[] = []
const workerNodes = reactFlowNodes.filter((node) => node.data.name === 'worker')
const supervisorNodes = reactFlowNodes.filter((node) => node.data.name === 'supervisor')
@@ -221,6 +222,9 @@ export const buildAgentGraph = async (
const sourceDocuments = output[agentName]?.messages
? output[agentName].messages.map((msg: BaseMessage) => msg.additional_kwargs?.sourceDocuments)
: []
const artifacts = output[agentName]?.messages
? output[agentName].messages.map((msg: BaseMessage) => msg.additional_kwargs?.artifacts)
: []
const messages = output[agentName]?.messages
? output[agentName].messages.map((msg: BaseMessage) => (typeof msg === 'string' ? msg : msg.content))
: []
@@ -240,6 +244,11 @@ export const buildAgentGraph = async (
if (cleanedDocs.length) totalSourceDocuments.push(...cleanedDocs)
}
if (artifacts && artifacts.length) {
const cleanedArtifacts = artifacts.filter((artifact: ICommonObject) => artifact)
if (cleanedArtifacts.length) totalArtifacts.push(...cleanedArtifacts)
}
/*
* Check if the next node is a condition node, if yes, then add the agent reasoning of the condition node
*/
@@ -273,6 +282,7 @@ export const buildAgentGraph = async (
instructions: output[agentName]?.instructions,
usedTools: flatten(usedTools) as IUsedTool[],
sourceDocuments: flatten(sourceDocuments) as Document[],
artifacts: flatten(artifacts) as ICommonObject[],
state,
nodeName: isSequential ? mapNameToLabel[agentName].nodeName : undefined,
nodeId
@@ -395,10 +405,12 @@ export const buildAgentGraph = async (
totalSourceDocuments = uniq(flatten(totalSourceDocuments))
totalUsedTools = uniq(flatten(totalUsedTools))
totalArtifacts = uniq(flatten(totalArtifacts))
if (shouldStreamResponse && sseStreamer) {
sseStreamer.streamUsedToolsEvent(chatId, totalUsedTools)
sseStreamer.streamSourceDocumentsEvent(chatId, totalSourceDocuments)
sseStreamer.streamArtifactsEvent(chatId, totalArtifacts)
sseStreamer.streamEndEvent(chatId)
}
@@ -406,6 +418,7 @@ export const buildAgentGraph = async (
finalResult,
finalAction,
sourceDocuments: totalSourceDocuments,
artifacts: totalArtifacts,
usedTools: totalUsedTools,
agentReasoning
}