Skip to content

Commit

Permalink
Merge pull request #4 from ai-made-approachable/return_graph_output
Browse files Browse the repository at this point in the history
Optionally return graph output (non streaming)
  • Loading branch information
ai-made-approachable authored Feb 3, 2024
2 parents a5ffd3b + e6a3fbf commit e4aa563
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 26 deletions.
12 changes: 8 additions & 4 deletions config/default.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
{
"file": "./example.rivet-project",
"graphName": "chat-history",
"nodeType": "chat",
"nodeName": "Output (Chat)",
"graphInput": "input"
}
"graphInputName": "input",
"streamingOutput": {
"nodeType": "chat",
"nodeName": "Output (Chat)"
},
"returnGraphOutput": false,
"graphOutputName": "output"
}
24 changes: 9 additions & 15 deletions dist/graphManager.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/graphManager.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion example.rivet-data
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"datasets":[{"meta":{"id":"J-3PhzWvBMkJHEu6dQLX1","projectId":"vHpwmvjUYbE-MQJ7H_sV_","name":"New Dataset","description":""},"data":{"id":"J-3PhzWvBMkJHEu6dQLX1","rows":[]}}]}
{"datasets":[]}
14 changes: 9 additions & 5 deletions src/graphManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class GraphManager {
this.startDebuggerServerIfNeeded();
const projectContent = await fs.readFile(config.get('file'), 'utf8');
const project = loadProjectFromString(projectContent);
const graphInput = config.get('graphInput') as string;
const graphInput = config.get('graphInputName') as string;

const options = {
graph: config.get('graphName'),
Expand Down Expand Up @@ -65,8 +65,8 @@ class GraphManager {
for await (const event of processor.events()) {
if (
event.type === 'partialOutput' &&
event.node.type === config.get('nodeType') &&
event.node.title === config.get('nodeName')
event.node.type === config.get('streamingOutput.nodeType') &&
event.node.title === config.get('streamingOutput.nodeName')
) {
const content = (event.outputs as any).response.value;
this.output = content; // Update the output variable with the content
Expand All @@ -81,7 +81,11 @@ class GraphManager {

console.log('Finished processing events'); // Debugging line

await runPromise;
const finalOutputs = await runPromise;
// Also return the graph output if returnGraphOutput is configured as true
if(config.get('returnGraphOutput')) {
yield finalOutputs[config.get('graphOutputName')].value;
}
this.isRunning = false;

console.log('runGraph finished'); // Debugging line
Expand All @@ -91,7 +95,7 @@ class GraphManager {
this.isRunning = false;
}
}

getOutput() {
return this.output;
}
Expand Down

0 comments on commit e4aa563

Please sign in to comment.