feat: solution for 'Повторный экзамен: Граф с рефлексией и доработкой'
This commit is contained in:
+40
-5
@@ -1,6 +1,41 @@
|
||||
/**
|
||||
* Export the Graph class for external use.
|
||||
* This file contains no IDE-generated boilerplate.
|
||||
*/
|
||||
const Graph = require('./graph');
|
||||
module.exports = { Graph };
|
||||
const { reflect } = require('./nodes/reflect');
|
||||
const { rewrite } = require('./nodes/rewrite');
|
||||
|
||||
/**
|
||||
* Entry point of the application.
|
||||
* Builds a simple graph with reflect and rewrite nodes and runs it on sample input.
|
||||
*/
|
||||
async function main() {
|
||||
// Ensure the OpenAI API key is set
|
||||
if (!process.env.OPENAI_API_KEY) {
|
||||
console.error('Error: OPENAI_API_KEY environment variable is not set.');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// Create graph and add nodes
|
||||
const graph = new Graph();
|
||||
graph.addNode('reflect', reflect);
|
||||
graph.addNode('rewrite', rewrite);
|
||||
|
||||
// Sample input message
|
||||
const inputMessage = 'I am feeling overwhelmed with my workload and unsure how to prioritize tasks.';
|
||||
|
||||
console.log('--- Input Message ---');
|
||||
console.log(inputMessage);
|
||||
console.log('---------------------\n');
|
||||
|
||||
try {
|
||||
// Execute the graph: first reflect, then rewrite
|
||||
const finalOutput = await graph.run(['reflect', 'rewrite'], inputMessage);
|
||||
|
||||
console.log('--- Final Output ---');
|
||||
console.log(finalOutput);
|
||||
console.log('---------------------');
|
||||
} catch (err) {
|
||||
console.error('An error occurred during graph execution:');
|
||||
console.error(err.message);
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
||||
Reference in New Issue
Block a user