feat: solution for 'Повторный экзамен: Граф с рефлексией и доработкой'
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
import { app } from './langgraph';
|
||||
|
||||
async function main() {
|
||||
const result = await app.invoke({ input: 'Hello world' });
|
||||
console.log('Final result:', result);
|
||||
}
|
||||
|
||||
main().catch((err) => {
|
||||
console.error('Error during execution:', err);
|
||||
});
|
||||
@@ -0,0 +1,41 @@
|
||||
import { StateGraph } from 'langgraph';
|
||||
|
||||
export type State = {
|
||||
input: string;
|
||||
output?: string;
|
||||
};
|
||||
|
||||
const startFn = (state: State) => {
|
||||
// The start node simply passes the initial state through.
|
||||
return state;
|
||||
};
|
||||
|
||||
const reflection = (state: State) => {
|
||||
console.log('Reflection node:', state);
|
||||
return state;
|
||||
};
|
||||
|
||||
const rewriting = (state: State) => {
|
||||
const newState = { ...state, output: state.input.toUpperCase() };
|
||||
console.log('Rewriting node:', newState);
|
||||
return newState;
|
||||
};
|
||||
|
||||
const end = (state: State) => {
|
||||
console.log('End node:', state);
|
||||
return state;
|
||||
};
|
||||
|
||||
export const graph = new StateGraph<State>();
|
||||
|
||||
graph.addNode('start', startFn);
|
||||
graph.addNode('reflection', reflection);
|
||||
graph.addNode('rewriting', rewriting);
|
||||
graph.addNode('end', end);
|
||||
|
||||
graph.setEntryPoint('start');
|
||||
graph.addEdge('start', 'reflection');
|
||||
graph.addEdge('reflection', 'rewriting');
|
||||
graph.addEdge('rewriting', 'end');
|
||||
|
||||
export const app = graph.compile();
|
||||
Reference in New Issue
Block a user