1.4 KiB
1.4 KiB
Graph with Reflection on Code
This repository contains a simple Python implementation of a graph that performs reflection on code snippets using LangGraph and an OpenAI LLM.
Requirements
- Python 3.10+
langgraphlangchain-openaiopenai
Setup
- Create a virtual environment (optional but recommended):
python -m venv venv
source venv/bin/activate # On Windows: venv\\Scripts\\activate
- Install dependencies:
pip install -r requirements.txt
- Set your OpenAI API key:
export OPENAI_API_KEY="your_api_key_here"
Running the Graph
The graph is defined in src/main.py. To run it with a sample code snippet:
python src/main.py
You should see a reflection printed to the console.
Using the Graph Programmatically
You can import the run_graph function from src/main.py and pass any code snippet:
from src.main import run_graph
code = """
def add(a, b):
return a + b
"""
reflection = run_graph(code)
print(reflection)
How Reflection Works
The graph has three nodes:
- Input Node – Receives the code snippet.
- Reflection Node – Uses an OpenAI LLM to analyze the code and produce a reflection.
- Output Node – Returns the reflection.
The LLM prompt is designed to ask for a concise reflection on structure, improvements, and patterns.
License
MIT License