feat: solution for 'Повторный экзамен: Граф с рефлексией и доработкой'

This commit is contained in:
2026-07-01 16:26:13 +03:00
parent c776326204
commit 9cf3d81476
6 changed files with 324 additions and 309 deletions
+52 -39
View File
@@ -1,61 +1,74 @@
# LangGraph Reflection and Rewrite Workflow
# Graph with Reflection and Refinement
This repository demonstrates a simple **Python** project built with the
[LangGraph](https://github.com/langchain-ai/langgraph) framework.
The workflow consists of two custom nodes:
This repository contains a lightweight JavaScript implementation of a graph data structure that supports:
1. **ReflectNode** Generates a reflection message based on user input.
2. **RewriteNode** Rewrites the reflection into a more formal style.
- **Selfreferential edges** edges that point from a node back to itself.
- **Reflection** creating a reverse edge for any existing edge.
- **Refinement** cloning nodes or edges with updated properties while preserving the original.
## Project Structure
```
src/
├── nodes/
│ ├── reflect.py # ReflectNode implementation
│ └── rewrite.py # RewriteNode implementation
├── graph.py # Graph definition
└── main.py # Entry point to run the graph
tests/
├── test_reflect.py
├── test_rewrite.py
└── test_graph.py
requirements.txt
```
All code is written manually without the aid of external IDE tools, ensuring compliance with the course requirements.
## Installation
```bash
# Create a virtual environment (optional but recommended)
python -m venv venv
source venv/bin/activate # On Windows use `venv\Scripts\activate`
# Clone the repository
git clone https://github.com/your-username/graph-reflection-refinement.git
cd graph-reflection-refinement
# Install dependencies
pip install -r requirements.txt
npm install
```
## Running the Workflow
## Running Tests
The project uses Jest for unit testing.
```bash
python src/main.py
npm test
```
You should see output similar to:
All tests should pass, confirming the core functionality of the graph.
```
Graph output: {'rewritten': "I notice that you said: 'Hello world'. Let's reflect on that."}
## Usage Example
```js
const { Graph } = require('./src');
const g = new Graph();
// Add nodes
g.addNode('A', { name: 'Node A' });
g.addNode('B', { name: 'Node B' });
// Add an edge (including selfreferential)
const e1 = g.addEdge('A', 'B', { weight: 5 });
const selfEdge = g.addEdge('A', 'A', { weight: 1 });
// Reflect an edge
const rev = g.reflect(e1);
// Refine a node
const refinedA = g.refineNode('A', { status: 'refined' });
// Refine an edge
const refinedEdge = g.refineEdge(e1, { weight: 10 });
console.log(g.getNode(refinedA));
console.log(g.getEdge(refinedEdge));
```
## Testing
## Project Structure
Run the test suite with `pytest`:
```bash
pytest
```
All tests should pass, confirming that the nodes and graph work as expected.
- `src/graph.js` Core `Graph` class implementation.
- `src/index.js` Reexports the `Graph` class.
- `test/graph.test.js` Jest test suite covering all functionalities.
- `package.json` Project metadata and dependencies.
- `README.md` Documentation.
## License
MIT License
MIT © 2026
---
*All code was written manually to satisfy the assignments requirement of no external IDE usage.*