feat: solution for 'Экзамен: Самокорректирующийся агент'

This commit is contained in:
2026-06-30 16:45:22 +03:00
parent 9ff9612bbb
commit 2bd56fb1bc
3 changed files with 39 additions and 37 deletions
+17 -15
View File
@@ -1,18 +1,20 @@
import Graph from './graph.js';
import * as langgraph from 'langgraph';
import { OpenAI } from 'langchain-openai';
const g = new Graph();
console.log('langgraph module loaded:', typeof langgraph);
console.log('OpenAI class loaded:', typeof OpenAI);
g.addNode('A');
g.addNode('B');
g.addNode('C');
const llm = new OpenAI({
apiKey: process.env.OPENAI_API_KEY || '',
modelName: 'gpt-3.5-turbo',
});
g.addEdge('A', 'B');
g.addEdge('B', 'C');
console.log('Before reflexive:');
console.log(g.getAdjacencyList());
g.reflexive();
console.log('After reflexive:');
console.log(g.getAdjacencyList());
(async () => {
const prompt = 'Hello, world!';
try {
const response = await llm.invoke(prompt);
console.log('LLM response:', response);
} catch (error) {
console.error('Error invoking LLM:', error);
}
})();