-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #306 from isamu/streamingSample
add openai streaming sample
- Loading branch information
Showing
2 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import "dotenv/config"; | ||
|
||
import { GraphAI } from "@/graphai"; | ||
|
||
import { AgentFunctionContext } from "@/type"; | ||
import { openAIAgent } from "@/experimental_agents/llm_agents/openai_agent"; | ||
import { streamAgentFilterGenerator } from "@/experimental_agent_filters/stream"; | ||
|
||
const streamData: Record<string, string> = {}; | ||
|
||
const outSideFunciton = (context: AgentFunctionContext, data: string) => { | ||
const nodeId = context.debugInfo.nodeId; | ||
streamData[nodeId] = (streamData[nodeId] || "") + data; | ||
console.log(streamData); | ||
}; | ||
|
||
const agentFilters = [ | ||
{ | ||
name: "streamAgentFilter", | ||
agent: streamAgentFilterGenerator<string>(outSideFunciton), | ||
}, | ||
]; | ||
|
||
|
||
const graph_data = { | ||
version: 0.3, | ||
nodes: { | ||
node1: { | ||
value: "Please tell me about photosynthesis in 50 words.", | ||
}, | ||
node2: { | ||
agent: "openAIAgent", | ||
inputs: [":node1"], | ||
isResult: true, | ||
}, | ||
}, | ||
}; | ||
|
||
export const main = async () => { | ||
// const result = await graphDataTestRunner(__filename, graph_data, { openAIAgent }, { agentFilters }); | ||
const graph = new GraphAI(graph_data, { openAIAgent }, { agentFilters }); | ||
const result = await graph.run(); | ||
console.log(JSON.stringify(result)); | ||
|
||
console.log("COMPLETE 1"); | ||
}; | ||
|
||
if (process.argv[1] === __filename) { | ||
main(); | ||
} |
File renamed without changes.